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. 《软件开发与创新:ThoughtWorks文集:续集》

    <软件开发与创新:ThoughtWorks文集:续集> 基本信息 原书名:The thoughtWorks anthology, volume 2:More essays on softw ...

  2. iOS:NSDate的主要几种时间形式

    NSDate:时间的获取和操作 1.获取当前时间 //获取当前日期 NSDate *date = sender.date; NSLog(@"%@",date); 2.将date转换 ...

  3. go语言基础之切片和底层数组关系

    1.切片和底层数组关系 示例: package main //必须有个main包 import "fmt" func main() { a := []int{0, 1, 2, 3, ...

  4. 锐浪报表 导出 PDF ANSI码 乱码 问题解决

    锐浪 报表 导出PDF时如果 ANSI 码 打勾了会乱码,能将这个选项默认不打勾吗 //在报表导出事件脚本里写脚本,可实现导出控制Sender.AsE2PDFOption.AnsiTextMode=0 ...

  5. POJ 1651 Multiplication Puzzle (区间DP)

    Description The multiplication puzzle is played with a row of cards, each containing a single positi ...

  6. 游戏服务器框架:Leaf/go

    Leaf 是一个使用 Go 语言开发的开源游戏服务器框架,注重运行效率并追求极致的开发效率.Leaf 适用于几乎所有的游戏类型.其主要的特性: 良好的使用体验.Leaf 总是尽可能的提供简洁和易用的接 ...

  7. Android -- SlidingMenu

    实现原理 在一个Activity的布局中需要有两部分,一个是菜单(menu)的布局,一个是内容(content)的布局.两个布局横向排列,菜单布局在左,内容布局在右.初始化的时候将菜单布局向左偏移,以 ...

  8. 防止excel数字变成科学计数法

    在网上查了很多资料知道解决办法大概有两个:一是在身份证字段前加个英文单引号,二是设置Excel的格式为文本格式. 我试用过第一种确实可以显示,但是有个“'”号在那里感觉确实不是很好,虽然听说不影响,但 ...

  9. C++中用完需要释放掉内存的几个类

      BSTR BSTR bstrXML = NULL; //用完以后,或者 catch段中 if(bstrXML) ::SysFreeString(result); VARIANT VARIANT v ...

  10. [mysql] C++操作mysql方法总结(1)

    From: http://www.cnblogs.com/magicsoar/p/3817518.html C++通过mysql的c api和通过mysql的Connector C++ 1.1.3操作 ...