HDU 4727 The Number Off of FFF

来源:互联网 发布:百度软件开发工程师 编辑:程序博客网 时间:2024/06/05 08:09
X soldiers from the famous " *FFF* army" is standing in a line, from left to right. 
You, as the captain of *FFF*, decides to have a "number off", that is, each soldier, from left to right, calls out a number. The first soldier should call "One", each other soldier should call the number next to the number called out by the soldier on his left side. If every soldier has done it right, they will call out the numbers from 1 to X, one by one, from left to right. 
Now we have a continuous part from the original line. There are N soldiers in the part. So in another word, we have the soldiers whose id are between A and A+N-1 (1 <= A <= A+N-1 <= X). However, we don't know the exactly value of A, but we are sure the soldiers stands continuously in the original line, from left to right. 
We are sure among those N soldiers, exactly one soldier has made a mistake. Your task is to find that soldier.
Input
The rst line has a number T (T <= 10) , indicating the number of test cases. 
For each test case there are two lines. First line has the number N, and the second line has N numbers, as described above. (3 <= N <= 10 5
It guaranteed that there is exactly one soldier who has made the mistake.
Output
For test case X, output in the form of "Case #X: L", L here means the position of soldier among the N soldiers counted from left to right based on 1.
Sample Input
231 2 431001 1002 1004
Sample Output
Case #1: 3

Case #2: 3

奇怪的题目,总感觉题目是有问题的,对于第一个点的判断太奇怪了。

#include<map>   #include<set>  #include<ctime>    #include<cmath>   #include<stack>#include<queue>     #include<string>    #include<vector>    #include<cstdio>        #include<cstring>      #include<iostream>    #include<algorithm>        #include<functional>    using namespace std;#define ms(x,y) memset(x,y,sizeof(x))        #define rep(i,j,k) for(int i=j;i<=k;i++)        #define per(i,j,k) for(int i=j;i>=k;i--)        #define loop(i,j,k) for (int i=j;i!=-1;i=k[i])        #define inone(x) scanf("%d",&x)        #define intwo(x,y) scanf("%d%d",&x,&y)        #define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)      #define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p)     #define lson x<<1,l,mid    #define rson x<<1|1,mid+1,r    #define mp(i,j) make_pair(i,j)    #define ff first    #define ss second    typedef long long LL;typedef pair<int, int> pii;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 1e5 + 10;const double eps = 1e-10;int T, n, cas = 1, a[N];int main(){for (inone(T); T--; cas++){inone(n);rep(i, 1, n) inone(a[i]);printf("Case #%d: ", cas);int flag = 0;rep(i, 2, n){if (a[1] + i - 1 != a[i]){printf("%d\n", i);flag = 1; break;}}if (!flag) puts("1");}return 0;}

0 0