本文共 2630 字,大约阅读时间需要 8 分钟。
1001
There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose.
There is a number T shows there are T test cases below. ( T≤10 ) For each test case , the first line contains a integers n , which means the number of numbers the permutation has. In following a line , there are n distinct postive integers.( 1≤n≤1,000 )
For each case output two numbers , small number first.
233 4 511
1 22 3
解题思路:题意给的n个数是1~n+2之间的数,因此只需要将在1~n+2之间却不在给定的n个数的数找出来即可。
参考代码:
#include1002#include #include #include #include using namespace std;typedef long long ll;int main(){ int n,t,a; bool used[1003]; cin>>t; while (t--){ cin>>n; memset(used,false,sizeof(used)); for (int i=0;i >a; used[a]=true; } int flag=0; for (int i=1;i<=n+2;i++){ if (used[i]==false){ flag++; if (flag==1) cout< <<" "; if (flag==2) cout<<
Following is the recursive definition of Fibonacci sequence: Fi=⎧⎩⎨01Fi−1+Fi−2i = 0i = 1i > 1 Now we need to check whether a number can be expressed as the product of numbers in the Fibonacci sequence.
There is a number T shows there are T test cases below. ( T≤100,000 ) For each test case , the first line contains a integers n , which means the number need to be checked. 0≤n≤1,000,000,000
For each case output "Yes" or "No".
3417233
YesNoYes
解题思路:首先用一个数组将fib数列保存下来,然后求出用一个数组将Fibonacci数组中属于n的因子的数保存,最后在递归搜索求解是否存在n是这些Fibonacci数组成的积;
参考代码:
#include#include #include #include #include #include #include using namespace std;int fib[100],a[100],i,k;bool work(int n,int step){ //递归搜索求解是否存在n是这些Fibonacci数组成的积 if (n==1) return true; for (int j=step;j >t; while (t--){ cin>>n; if (n==0){ cout<<"Yes"<
转载地址:http://bfbqb.baihongyu.com/