今天在家接受洗脑运动,因此又没有做BC,洗脑完毕后看了下前两题,嗯不难,第二题一开始理解错题意跪了一发,后来知道了方法再写发现写挫了T了一发,才过的OTL。。。
Missing number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 114 Accepted Submission(s): 60
Problem Description
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.
Input
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 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 )
Output
For each case output two numbers , small number first.
Sample Input
2 3 3 4 5 1 1
Sample Output
1 2 2 3
水吧,直接标记一下出现了的,没出现的输出就好了。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int m;
m=n+2;
bool check[1005];
for(int i=1;i<=m;i++)
{
check[i]=0;
}
while(n--)
{
int a;
cin>>a;
check[a]=1;
}
int ans[10];
int cnt=0;
for(int i=1;i<=m;i++)
{
if(check[i]==0)
{
ans[cnt++]=i;
}
}
cout<<ans[0]<<" "<<ans[1]<<endl;
}
}
Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 391 Accepted Submission(s): 110
Problem Description
Following is the recursive definition of Fibonacci sequence:
Now we need to check whether a number can be expressed as the product of numbers in the 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.
Input
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 test case , the first line contains a integers n , which means the number need to be checked.
0≤n≤1,000,000,000
Output
For each case output "Yes" or "No".
Sample Input
3 4 17 233
Sample Output
Yes No Yes
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
long long fib[50];
map<long long,int> mp;
queue<long long> q;
void slove()
{
fib[0]=0;
fib[1]=1;
long long cnt;
for(long long i=2;;i++)
{
fib[i]=fib[i-1]+fib[i-2];
if(fib[i]>1000000000)
{
cnt=i;
break;
}
}
for(long long i=0;i<cnt;i++)
{
q.push(fib[i]);
}
while(!q.empty())
{
long long x=q.front();
q.pop();
if(x>1000000000||mp[x]>0)
continue;
else
mp[x]++;
for(long long i=0;i<cnt;i++)
{
long long tmp=x*fib[i];
if(tmp>1000000000)
break;
else
q.push(tmp);
}
}
}
int main()
{
long long t;
slove();
cin>>t;
while(t--)
{
long long n;
cin>>n;
if(mp[n])
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
return 0;
}