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
 此题解法多样,关键是要理解其意思....
题意为:
 从左向右依次报数,但是必定有一人报错,其中报错的意思是数据是任意的...比如 1 2 3 4 4 5 6 or 1 2 3 1 2
等 所以只需要比较这项是否是上一项+1即可。。。。
代码如下:
 #include<iostream>
#include<cstdio>
#include<cstring>
#define maxn 100000
using namespace std;
int str[maxn+];
int main()
{
int t,n,count,i;
scanf("%d",&t);
for(count=;count<=t;count++)
{
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",str+i);
}
if(str[i=]>)
{
for(i=;i<n;i++)
if(str[i-]+!=str[i])
break;
}
printf("Case #%d: %d\n",count,(i%n)+);
}
return ;
}

HDUOJ----The Number Off of FFF的更多相关文章

  1. 水题 HDOJ 4727 The Number Off of FFF

    题目传送门 /* 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 */ #include <cstdio> #include <iostream> ...

  2. 周赛-The Number Off of FFF 分类: 比赛 2015-08-02 09:27 3人阅读 评论(0) 收藏

    The Number Off of FFF Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU 4727 The Number Off of FFF

    The Number Off of FFF Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

  4. HDU 4727 The Number Off of FFF (水题)

    The Number Off of FFF Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. The Number Off of FFF

    X soldiers from the famous “FFF army'' is standing in a line, from left to right. You, as the captai ...

  6. hdu4727 The Number Off of FFF

    理解错题意,wa了几次. 我一开始的理解忽略了实际背景,认为错报是绝对的,不依赖于其左边的人. 而实际上某士兵报数的对错取决且仅取决于他所报的数与其左邻所报的数. 所以假设第一个人没有报错,则其后必有 ...

  7. HDU-4727 The Number Off of FFF 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4727 水题.. //STATUS:C++_AC_187MS_288KB #include <fu ...

  8. HDU 4727 The Number Off of FFF 2013年四川省赛题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4727 题目大意:队列里所有人进行报数,要找出报错的那个人 思路:,只要找出序列中与钱一个人的数字差不是 ...

  9. 移除input number上的spinner

    HTML 5 的表单中有着丰富的input种类,比如说input[type="number"],就可以保证用户输入数字,但是input也有一些不好的地方——带有 spinner. ...

随机推荐

  1. Python for everyone chapter 1

    Chapter 1 10 试题 1.  When Python is running in the interactive mode and displaying the chevron prompt ...

  2. http状态码的含义及502, 503和504的区别

    https://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81#5xx%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%94%9 ...

  3. Java 从基础到进阶学习之路---类编写以及文档凝视.

    Java之前在学习过,基础知识还没有忘光,并且这些高级语言实在是太像,所以那些数据类型,或者循环控制流,以及标准设备等等就直接略过不说了. 只是一些重大概念会穿插在文章的介绍中. So,这些文章适合于 ...

  4. Linq编程小趣味爱因斯坦谜题

    最近看到一个比较老的题目,题目----在一条街上,有5座房子,喷了5种颜色,每个房里住着不同国籍的人,每个人喝不同的饮料,抽不同品牌的香烟,养不同的宠物,问题---谁养鱼? 以前没事还做过这个题,现在 ...

  5. 给开发者准备的 10 款最好的 jQuery 日历插件[转]

    这篇文章介绍的是 10 款最棒而且又很有用的 jQuery 日历插件,允许开发者们把这些漂亮的日历插件结合到自己的网站中.这些日历插件易用性都很强,轻轻松松的就可以把漂亮的日历插件装饰到你的网站了.希 ...

  6. SQL锁(转)

    说 明    Chaos 无法改写隔离级别更高的事务中的挂起的更改.   ReadCommitted 在正在读取数据时保持共享锁,以避免脏读,但是在事务结束之前可以更改数据,从而导致不可重复的读取或幻 ...

  7. JDBC具体解释(2)

    1.载入驱动程序. 注冊驱动程序有多方法,Class.forName();是一种显式地载入.当一个驱动程序类被Classloader装载后,在溶解的过程中,DriverManager会注冊这个驱动类的 ...

  8. Android -- 加载大图片的方法

    在android中要加载一张大图片到内存中如果通过如下方式进行: Bitmap bitmap= BitmapFactory.decodeFile("/sdcard/a.jpg"); ...

  9. Python标准库:内置函数abs(x)

    返回数字的绝对值. 參数能够是整数或浮点数.假设參数是复数,则返回复数的模. 因此abs()函数的注意点就是复数的不一样计算方式. 样例: #正整数 print('abs(1):', abs(1)) ...

  10. Java从零开始学一(环境配置)

      一.JDK的下载和安装 1.下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151. ...