BestCoder Round #28
2015-02-01 08:42
239 查看
1001
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 748 Accepted Submission(s): 275
Problem Description
Input
Output
Sample Input
Sample Output
题意:给你n个数,问哪两个数丢失。
解题思路:题意给的n个数是1~n+2之间的数,因此只需要将在1~n+2之间却不在给定的n个数的数找出来即可。
参考代码:
1002
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 996 Accepted Submission(s): 40
Problem Description
Input
Output
Sample Input
Sample Output
题意:给出fib数列,问任意给定的一个n是否可以是fib数列中的若干fib数的积;
解题思路:首先用一个数组将fib数列保存下来,然后求出用一个数组将Fibonacci数组中属于n的因子的数保存,最后在递归搜索求解是否存在n是这些Fibonacci数组成的积;
参考代码:
Missing number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 748 Accepted Submission(s): 275
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)
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个数,问哪两个数丢失。
解题思路:题意给的n个数是1~n+2之间的数,因此只需要将在1~n+2之间却不在给定的n个数的数找出来即可。
参考代码:
#include <iostream> #include <string.h> #include <iomanip> #include <algorithm> #include <cmath> 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<n;i++){ cin>>a; used[a]=true; } int flag=0; for (int i=1;i<=n+2;i++){ if (used[i]==false){ flag++; if (flag==1) cout<<i<<" "; if (flag==2) cout<<i<<endl; } } } return 0; }
1002
Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 996 Accepted Submission(s): 40
Problem Description
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.
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
Output
For each case output "Yes" or "No".
Sample Input
3 4 17 233
Sample Output
Yes No Yes
题意:给出fib数列,问任意给定的一个n是否可以是fib数列中的若干fib数的积;
解题思路:首先用一个数组将fib数列保存下来,然后求出用一个数组将Fibonacci数组中属于n的因子的数保存,最后在递归搜索求解是否存在n是这些Fibonacci数组成的积;
参考代码:
#include <iostream> #include <stdio.h> #include <algorithm> #include <queue> #include <stack> #include <cmath> #include <string.h> 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<k;j++){ if (n%a[j]==0){ if (work(n/a[j],j)==true) return true; } } return false; } int main(){ int t,n; /*构造Fibonacci数组*/ fib[0]=0; fib[1]=1; for (i=2;i<46;i++){ fib[i]=fib[i-1]+fib[i-2]; } cin>>t; while (t--){ cin>>n; if (n==0){ cout<<"Yes"<<endl; continue; } k=0; for (int j=3;j<46;j++){ //用一个数组将Fibonacci数组中属于n的因子的数保存 if (n%fib[j]==0) a[k++]=fib[j]; } if (work(n,0)==true) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
相关文章推荐
- Bestcoder BestCoder Round #28 A Missing number(查找缺失的合法数字)
- BestCoder Round #28
- 【HDU5636 BestCoder Round 74 (div1)A】【floyd 最短路 复杂度考核】Shortest Path 一条链3条边1e6个询问的两点最短路
- BestCoder Round #75 解题报告
- BestCoder Round #75 T3 King's Order HDOJ 5642
- 【HDU5647 BestCoder Round 76 (div1)B】【树形DP】DZY Loves Connecting 一棵树的所有生成子树的大小乘积
- BestCoder Round #64 Sum
- BestCoder Round #40
- 【HDU5749 BestCoder Round 84C】【ST-RMQ?NO!暴力跳法or单调栈法 + 贡献思维】Colmerauer 所有子矩阵size乘鞍点权值和
- 【HDU5805 BestCoder Round 86B】【前后缀和】NanoApe Loves Sequence 删除一数后数列max(相邻数绝对值)
- BestCoder Round #50 (div.2) 1001
- HDU 5147 Ferries Wheel(暴力 数组)——BestCoder Valentine's Day Round
- hdu4858 项目管理 bestcoder round1 B
- 【HDU5188 BestCoder Round 33C】【贪心排序+DP】zhx and contest 考试不被怀疑作弊条件下达到至少m分的最少时间
- BestCoder Round #65 ZYB's Game
- 【BestCoder Round 65D】【树形DP 容斥思想】ZYB's Tree 求距离每个节点距离不超过k的节点数
- Bestcoder round 18----B题(一元三次方程确定区间的最大值(包含极值比较))
- 【HDU5637 BestCoder Round 74 (div1)B】【bfs预处理】Transform 15个值+17个2的幂数最小异或步数使得s变成t
- BestCoder Round #75
- BestCoder Round #25 1002 Harry And Magic Box [dp]