BestCoder#28两道水题 HDU5166&&5167

今天在家接受洗脑运动,因此又没有做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. ( T10 )
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.( 1n1,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
 
已知现在有长度为N+2的序列,然后丢失了两个数,给你现在有的N个数(互不相同),求丢失的两个数。。

水吧,直接标记一下出现了的,没出现的输出就好了。

#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:
Fi=01Fi1+Fi2i = 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. ( T100,000 )
For each test case , the first line contains a integers n , which means the number need to be checked.
0n1,000,000,000
 

Output
For each case output "Yes" or "No".
 

Sample Input
  
  
3 4 17 233
 

Sample Output
  
  
Yes No Yes
给你一个N,判断是否可以写成若干个FIB数列中元素的乘积,一开始看成了两个,逗比的去先把那个FIB的表打出来,暴力找,结果跪了,后来觉得数据量不大,可以枚举可能出现的所有合法乘积,然后MAP记录,然后判断一下这个N是否出现过就OK了。全用LL,卡着过的OTL

#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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值