HDU - 5166 - Missing number && 5167 - Fibonacci

Missing number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 430    Accepted Submission(s): 233

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

Source

BestCoder Round #28

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int vis[1005];

int main() {
	int T, n;
	scanf("%d", &T);
	while(T--) {
		scanf("%d", &n);
		memset(vis, 0, sizeof(vis));
		int m = n + 2, a, b, flag = 1;
		while(n--) {
			scanf("%d", &a);
			vis[a] = 1;
		}
		for(int i=1; i<=m; i++) {
			if(!vis[i] && flag == 1) {
				a = i; flag = 2;
			}
			else if(!vis[i] && flag == 2) {
				b = i; break;
			}
		}
		printf("%d %d\n", a, b);
	}
	return 0;
} 

Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1312    Accepted Submission(s): 328

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

Source

BestCoder Round #28

AC代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#define LL long long
using namespace std;

const int MAX = 1000000010L;
LL fibo[50] = {0, 1};
map<LL, bool> ma;

void init() {
	queue<LL> q;
	int flag;
	for(int i=2; i<50; i++) {
		fibo[i] = fibo[i-1] + fibo[i-2];
		if(fibo[i] > MAX) {
			flag = i; break;
		}
	}

	for(int i = 0; i < flag; i++) {
		q.push(fibo[i]); ma[fibo[i]] = true;
	}

	while(!q.empty()) {
		LL tmp = q.front();
		q.pop();
		for(int i = 2; i <= flag; i++) {
			LL t = tmp*fibo[i];
			if(t > MAX) break;
			if(ma[t]) continue;
			else {
				ma[t] = true;
				q.push(t);
			}
		}
	}
}

int main() {
	init();
	LL T, n;
	cin >> T;
	while(T--) {
		cin >> n;
		if(ma[n]) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
} 
时间: 2024-12-22 05:52:47

HDU - 5166 - Missing number && 5167 - Fibonacci的相关文章

hdu 5166 Missing number

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5166 Missing number 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 t

hdu 5166 Missing number(。。。)

题意: 有一个排列,但少了两个数.给你少了这两个数的排列.找出是哪两个数. 思路: 看代码,,, 代码: int a[1005]; int main(){ int T; cin>>T; while(T--){ int n; cin>>n; mem(a,0); rep(i,1,n){ int x; scanf("%d",&x); a[x]=1; } int c[10]; int cn=0; rep(i,1,n+2) if(a[i]==0){ c[++cn]

hdu 5167 Fibonacci(DFS)

hdu 5167 Fibonacci 问题描述 斐波那契数列的递归定义如下: Fi=???01Fi?1+Fi?2i = 0i = 1i > 1 现在我们需要判断一个数是否能表示为斐波那契数列中的数的乘积. 输入描述 有多组数据,第一行为数据组数T(T≤100,000). 对于每组数据有一个整数n,表示要判断的数字. 0≤n≤1,000,000,000 输出描述 对于每组数据,如果可以输出"Yes",否则输出"No". 输入样例 3 4 17 233 输出样例

hdu 5167 Fibonacci

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5167 题意: fi[0]=0,fi[1]=1 fi[i]=fi[i-1]+fi[i-2] i>1 给出一个数n,问这个数能不能有fi[]相乘得来. 限制: 0 <= n <= 1e9 思路: 1e9以内的斐波那契数只有44个,用记忆化搜索可以解决这道题. C++ Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

hdu 1250 Hat&amp;#39;s Fibonacci

点击此处就可以传送hdu 1250 Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) You

HDU 1250: Hat&#39;s Fibonacci

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6925    Accepted Submission(s): 2279 Problem Description A Fibonacci sequence is calculated by adding the previous two members th

HDU 5166(缺失数查找输出)

HDU 5166 Time Limit:1000MS  Memory Limit:65536KB     64bit IO Format:%I64d & %I64u 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

LeetCode172 Factorial Trailing Zeroes. LeetCode258 Add Digits. LeetCode268 Missing Number

数学题 172. Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. (Easy) 分析:求n的阶乘中末位0的个数,也就是求n!中因数5的个数(2比5多),简单思路是遍历一遍,对于每个数,以此除以5求其因数5的个数,但会超时. 考虑到一个数n比他小

leetcode Missing Number

题目连接 https://leetcode.com/problems/missing-number/ Missing Number Description Given an array containing n distinct numbers taken from$ 0, 1, 2, ..., n$, find the one that is missing from the array. For example,Given nums = $[0, 1, 3]$ return $2$. Not