BestCoder Round #28
来源:互联网 发布:linux 修改密码 编辑:程序博客网 时间:2024/04/20 13:06
1001
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 numberT shows there areT test cases below. (T≤10 )
For each test case , the first line contains a integersn , which means the number of numbers the permutation has. In following a line , there aren distinct postive integers.(1≤n≤1,000 )
Output
For each case output two numbers , small number first.
Sample Input
233 4 511
Sample Output
1 22 3
解题思路:题意给的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 numberT shows there areT 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
3417233
Sample Output
YesNoYes
解题思路:首先用一个数组将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;elsecout<<"No"<<endl;}return 0;}
0 1
- BestCoder Round #28
- BestCoder Round #28
- Missing number (BestCoder Round #28A )
- Fibonacci (BestCoder Round #28 B)
- BestCoder Round #3 BestCoder Sequence
- bestcoder round #1
- BestCoder round #1
- BestCoder Round #1
- 【索引】BestCoder Round #2
- BestCoder Round #2
- 【索引】BestCoder Round #3
- BestCoder Round #3
- BestCoder Round #3 小记
- BestCoder Round #4 题解
- BestCoder Round #6
- BestCoder Round #8
- Bestcoder Round #9
- BestCoder Round #9
- 【BZOJ 1042】 [HAOI2008]硬币购物
- 微信公众平台开发 无高级接口账号获取用户基本信息
- 在项目中,过滤器如何配置?可以实现拦截!
- windows下gvim的配置文件
- Leetcode -- Remove Duplicates from Sorted Array II
- BestCoder Round #28
- iOS平台(移动平台)架构问题
- HDU2519 新生晚会【水题】【组合数】
- 专车:一边点赞,一边釜底抽薪;前路难探,内部利益出现分化
- 错误隐藏学习手记(一)
- Spring学习 8
- Spring学习 9
- 年终大学习之MySQL数据库优化学习笔记(五)
- 2 Linear Regression, Gradient descent