前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDUOJ----The Number Off of FFF

HDUOJ----The Number Off of FFF

作者头像
Gxjun
发布2018-03-21 12:47:16
7560
发布2018-03-21 12:47:16
举报
文章被收录于专栏:mlml

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即可。。。。

代码如下:

代码语言:javascript
复制
 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: %d\n",count,(i%n)+1);
25         }
26     return 0;
27 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • The Number Off of FFF
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档