HDUOJ----The Number Off of FFF

时间:2022-05-05
本文章向大家介绍HDUOJ----The Number Off of FFF,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

The Number Off of FFF

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 169    Accepted Submission(s): 83

Problem Description

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 <= 105) 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

2

3

1 2 4

3

1001 1002 1004

Sample Output

Case #1: 3

Case #2: 3

Source

2013 ACM/ICPC Asia Regional Online —— Warmup2

 此题解法多样,关键是要理解其意思....

题意为:

 从左向右依次报数,但是必定有一人报错,其中报错的意思是数据是任意的...比如 1 2 3 4 4 5 6 or 1 2 3 1 2

等 所以只需要比较这项是否是上一项+1即可。。。。

代码如下:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #define maxn 100000
 5 using namespace std;
 6 int str[maxn+10];
 7 int main()
 8 {
 9         int t,n,count,i;
10         scanf("%d",&t);
11         for(count=1;count<=t;count++)
12         {
13             scanf("%d",&n);
14             for(i=0;i<n;i++)
15             {
16                scanf("%d",str+i);
17             }
18             if(str[i=0]>0)
19             {
20                for(i=1;i<n;i++)
21                 if(str[i-1]+1!=str[i])
22                     break;
23             }
24            printf("Case #%d: %dn",count,(i%n)+1);
25         }
26     return 0;
27 }