The Number Off of FFF
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 first 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
这个题很好理解,就是一个序列,每个数比前一个数大一,如果不是就是错误的,要求输出错误的数
但是我有一个疑问,如果后面的都对,就第一个不对怎么办?
我跟同学商量了一下,但是他说不可能,是一遍输入一遍判断,一开始我以为我读错了,但是现在发现不是那回事好像,因为一开始要求输入几个数,然后再输入各个数,如果1 2 4 5该怎么办,这个算哪个错,然后我就不管不顾的写了代码,对了
#include<cstdio>
int main()
{
int t,n,x,j,i,y;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d",&n);
scanf("%d",&x);
int cnt=1;
for(j=2;j<=n;j++)
{
scanf("%d",&y);
if(y-x!=1)
{
cnt=j;
}
x=y;
}
printf("Case #%d: %d\n",i,cnt);
}
return 0;
}
同学写的就是考虑了我举得例子,他是按第一个是正确答案输出的
#include<stdio.h>
int main()
{
int T,N,i,j,k,temp,cnt,flag;
scanf("%d",&T);
for(i=1;i<=T;i++)
{
scanf("%d",&N);
scanf("%d",&temp);
flag=cnt=1;
for(j=2;j<=N;j++)
{
scanf("%d",&k);
if(k-temp!=1&&flag)
{cnt=j;flag=0;}
temp=k;
}
printf("Case #%d: %d\n",i,cnt);
}
return 0;
}
这个应该很好理解吧,水题啊
The Number Off of FFF的更多相关文章
- 水题 HDOJ 4727 The Number Off of FFF
题目传送门 /* 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 */ #include <cstdio> #include <iostream> ...
- 周赛-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 ...
- 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 ...
- 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 ...
- HDUOJ----The Number Off of FFF
The Number Off of FFF Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu4727 The Number Off of FFF
理解错题意,wa了几次. 我一开始的理解忽略了实际背景,认为错报是绝对的,不依赖于其左边的人. 而实际上某士兵报数的对错取决且仅取决于他所报的数与其左邻所报的数. 所以假设第一个人没有报错,则其后必有 ...
- HDU-4727 The Number Off of FFF 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4727 水题.. //STATUS:C++_AC_187MS_288KB #include <fu ...
- HDU 4727 The Number Off of FFF 2013年四川省赛题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4727 题目大意:队列里所有人进行报数,要找出报错的那个人 思路:,只要找出序列中与钱一个人的数字差不是 ...
- 移除input number上的spinner
HTML 5 的表单中有着丰富的input种类,比如说input[type="number"],就可以保证用户输入数字,但是input也有一些不好的地方——带有 spinner. ...
随机推荐
- python thrift 服务端与客户端使用
一.简介 thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, Java, Python, PHP, Ruby, Erlang, ...
- python爬虫学习-爬取某个网站上的所有图片
最近简单地看了下python爬虫的视频.便自己尝试写了下爬虫操作,计划的是把某一个网站上的美女图全给爬下来,不过经过计算,查不多有好几百G的样子,还是算了.就首先下载一点点先看看. 本次爬虫使用的是p ...
- sprint2总结
在sprint第二阶段的学习过程中,前期和后期在学校网络的支持下我们成功的延迟了把代码上传github的时间,在我们自己感觉上看,完成项目的质量比较理想,在经过sprint第一阶段的学习后,部分上的问 ...
- Ubuntu 14.04 编译安装 boost 1.58
简介 Boost is a set of libraries for the C++ programming language that provide support for tasks and s ...
- mysql和CSV
1.mysql导入和导出数据可以通过mysql命令或者mysqldump来完成.mysqldump可以导入和导出完整的表结构和数据.mysql命令可以导入和导出csv文件. 1.mysql支持导入和导 ...
- ThinkPHP3.1快速入门(1)基础
学习网址:http://www.thinkphp.cn/document/60.html
- Python之路----------内置函数
1.abs(x)绝对值 #coding=utf-8 a = 1 b = -2 print(abs(a)) print(abs(b)) 2.all(iterable)可迭代对象里面所有内容为真返回真,空 ...
- 构造函数this和base的区别
构造函数this和base的区别: this:调用的是本身,不能调用父类和子类的 base:调用父类的,不能调用本身的,但别人继承,可以调用 从中也可以得出另外个结果构造函数的运行过程 先从基类开始构 ...
- 无题 MVC
1. MVC 里controller 返回匿名类型, 在View里是访问不了匿名类型的字段,因为它是Internal Private, 必须定义强类型 2. 扩展view的方法 public stat ...
- 在Ubuntu 12.04下采用apt-get的方法安装Qt4
在Ubuntu 12.04下采用apt-get的方法安装Qt4 注:之前发表的一篇博客是采用编译源码的方式安装Qt4,这是很有用的方式,因为源码安装对于所有系统都是通用的,其次,在使用交叉编译器的时候 ...