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. 《Windows核心编程》第2章——字符和字符处理

    ANSI和UNICODE 计算char和wchar_t的长度都一样,都是5,但是二者在内存中的布局实际上是不同的:

  2. easyui 排序实现

    1.对easyui  datagrid 返回的数据,进行排序处理,便于搜索到我们的有用的信息. 例如: 2.datagrid 需要设置 sortable : true { field : 'crtTi ...

  3. LaTeX中的数学公式

    因为想在过年之前把论文写出来(虽然现在看来似乎痴人说梦),用word写PDE的公式简直是自己找虐,就想说自己研究一下LaTex,用起来发现这东西写格式性的文档真心甩word几个陈景润啊,出来的公式不仅 ...

  4. 【BestCoder】【Round#42】

    模拟+链表+DP Orz AK爷faebdc A Growin要跟全部的n个人握手共2n杯香槟,再加上每对关系的两杯香槟,直接统计邻接矩阵中1的个数,再加2n就是answer //BestCoder ...

  5. 【BZOJ】【1968】【AHOI2005】COMMON 约数研究

    数论 原谅我这么傻逼的题都不会做…… 或许写成数学公式的形式比较容易想到解法? $$ans=\sum_{i=1}^n \sum_{d|i} 1$$ ……是不是感觉很水呀……是吧……改成先枚举d再枚举 ...

  6. HDU 4462 DFS

    2012 Asia Hangzhou Regional Contest 给出N*N的矩阵,所有标记为0,当中有K个点标记为1.而且能够在该位置放置一个能够覆盖曼哈顿距离为r的草人.问最少放置几个草人, ...

  7. 用java解析在OpenStreetMap上下载的地图数据(SAX版,适合比较大的xml文件)

    java程序如下: package gao.map.preprocess; import java.io.BufferedWriter; import java.io.File; import jav ...

  8. 混沌数学之Kent模型

    相关软件:混沌数学之离散点集图形DEMO 相关代码: // http://wenku.baidu.com/view/7c6f4a000740be1e650e9a75.html // 肯特映射 clas ...

  9. DialogPlus

    项目地址:https://github.com/orhanobut/dialogplus  Demo地址:https://github.com/baiqiantao/DialogPlusTest co ...

  10. Android -- Camera聚焦流程

    Camera.java autoFocus()聚焦回调函数 @Override public void autoFocus() { //记录当前聚焦开始时间 mFocusStartTime = Sys ...