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. ...
随机推荐
- 双十二前夕爆京东12G数据泄露的真相是什么
今天早上手机上推送出京东12g数据泄漏的消息,随即搜了下网上的相关新闻,感觉舆论又一次的干了一件惊天地的事情,到底京东的哪所谓的12G的用户信息数据有没有泄漏?舆论为什么齐刷刷的在12月11日突然间爆 ...
- 【javaweb学习】XML和约束模式
xml:可扩展标记语言,w3c组织发布的,用于保存有关系的数据,作为配置文件,描述程序模块之间的关系 <?xml version="1.0" encoding="g ...
- jquery复习笔记
Jquery基础 让一个按钮灰掉 $("button").("disabled","true"); ance desc选择器(ance代表祖 ...
- WCF Security(转载)
WCF Security 主要包括 "Transfer Security"."Access Control"."Auditing" 几个部分 ...
- 在Mac OS X 下快速安装Nginx
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Helvetica; color: #8e68ff } p.p2 { margin: 0.0p ...
- net面试题
简述 private. protected. public. internal 修饰符的访问权限.答 . private : 私有成员, 在类的内部才可以访问. protected : 保护成 ...
- 第三篇:白话tornado源码之请求来了
上一篇<白话tornado源码之待请求阶段>中介绍了tornado框架在客户端请求之前所做的准备(下图1.2部分),本质上就是创建了一个socket服务端,并进行了IP和端口的绑定,但是未 ...
- equals == 比较
public class Equals{ public static void main(String[] args){ Interger n1=new Interger(47); Interger ...
- css补充、JavaScript、Dom
css补充: position: fixed:可以将标签固定在页面的某个位置 absolute+relative:通过两者的结合可以让标签在一个相对的位置 代码例子:(通过fixed标签将某些内容固定 ...
- nginx1.8安装nginx_concat_module及400错误解决办法
nginx安装concat模块可以合并js,css等静态资源,减少http请求 在nginx源码目录执行命令: ./configure --user=www --group=www --prefix= ...