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. DIV元素不换行

    DIV盒子默认是换行独占100%宽度:DIV盒子没有赋予CSS样式时,默认DIV盒子是独占一行(宽度为100%). 如下默认情况HTML代码: <!DOCTYPE html> <ht ...

  2. 最值得你所关注的10个C语言开源项目

    . Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接 ...

  3. Android Protobuf应用及原理

    前言 之前一直忙于移动端日志SDK Trojan的开源工作,已十分稳定地运行在饿了么团队App中,集成了日志加密和解密功能.哎呀,允许我卖个狗皮膏药,不用不知道,用了就知道,从此爱不释手,Trojan ...

  4. UCN(User-Centric Networks,用户中心网络)

    UCN(User-Centric Networks,以用户为中心的网络)是下一代移动通信网络(5G)的发展方向,目前尚处于初级发展阶段.2016年11月,IEEE SDN研究组(聚焦研发SDN.NFV ...

  5. 【BZOJ】【1007】【HNOI2008】水平可见直线

    计算几何初步 其实是维护一个类似下凸壳的东西?画图后发现其实斜率是单调递增的,交点的横坐标也是单调递增的,所以排序一下搞个单调栈来做就可以了…… 看了hzwer的做法…… /************* ...

  6. Java开发牛人十大必备网站

    以下是我收集的Java开发牛人必备的网站.这些网站可以提供信息,以及一些很棒的讲座, 还能解答一般问题.面试问题等.质量是衡量一个网站的关键因素,我个人认为这些网站质量都很好.接下来,我会跟大家分享我 ...

  7. C/C++字符串查找函数

    C/C++ string库(string.h)提供了几个字符串查找函数,如下: memchr 在指定内存里定位给定字符 strchr 在指定字符串里定位给定字符 strcspn 返回在字符串str1里 ...

  8. 【转载】Hybrid APP了解

    原文:http://uikoo9.com/blog/detail/hpp 不错的hybrid app框架:http://www.dcloud.io/case/#group-1 HPP hybirdAp ...

  9. C++ Jsoncpp源代码编译与解析Json

    1.Json 数据表示方式介绍 这个可以看之前的一个文章里面有说明:Java解析(读取)Json数据 2.C++ Jsoncpp 2.1 Jsoncpp介绍 (1)JsonCpp主要包含三种类型的cl ...

  10. go语言基础之结构体成员的使用普通变量

    1.结构体成员的使用普通变量 示例: package main //必须有个main包 import "fmt" //定义一个结构体类型 type Student struct { ...