2 3 3 4 5 1 1
1 2 2 3
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; }
3 4 17 233
Yes No Yes
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; }
HDU - 5166 - Missing number && 5167 - Fibonacci
原文地址:http://blog.csdn.net/u014355480/article/details/43622147