HDUOJ----The Number Off of FFF
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
2013 ACM/ICPC Asia Regional Online —— Warmup2
此题解法多样,关键是要理解其意思....
题意为:
从左向右依次报数,但是必定有一人报错,其中报错的意思是数据是任意的...比如 1 2 3 4 4 5 6 or 1 2 3 1 2
等 所以只需要比较这项是否是上一项+1即可。。。。
代码如下:
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #define maxn 100000
5 using namespace std;
6 int str[maxn+10];
7 int main()
8 {
9 int t,n,count,i;
10 scanf("%d",&t);
11 for(count=1;count<=t;count++)
12 {
13 scanf("%d",&n);
14 for(i=0;i<n;i++)
15 {
16 scanf("%d",str+i);
17 }
18 if(str[i=0]>0)
19 {
20 for(i=1;i<n;i++)
21 if(str[i-1]+1!=str[i])
22 break;
23 }
24 printf("Case #%d: %dn",count,(i%n)+1);
25 }
26 return 0;
27 }
- Spark源码系列(八)Spark Streaming实例分析
- “震网三代”(CVE-2017-8464)的几种利用方法与防范
- Spark1.0新特性-->Spark SQL
- 挖洞经验 | 看我如何综合利用4个漏洞实现GitHub Enterprise 远程代码执行
- Spark的机器学习算法mlib的例子运行
- Spark Streaming自定义Receivers
- 利用USB橡皮鸭在目标机器上启动Empire或Meterpreter会话
- Spark部署
- Spark调优
- perl语言十分钟入门【零基础可入】
- Spark硬件配置推荐
- Spark作业调度
- 如何把Photoshop改造成远程控制工具(RAT)来利用
- Office高级威胁漏洞在野利用分析
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 【Java集合-2】HashMap简析
- 【Java集合-3】ArrayList简析
- Springboot之Security前后端分离登录
- Windows 10使用WSL作为python宿主机调试开发
- 小米正式开源 SQL 智能优化与改写工具 SOAR
- 【SpringBoot-1】面向小白编程:从0开始创建一个SpringBoot项目
- 【SpringBoot-3】Lombok使用详解
- 【JMeter系列-3】JMeter元件详解之配置元件
- 【JMeter-4】JMeter元件详解之逻辑控制器
- 【JMeter-4】JMeter关联:JMeter正则表达式提取器与JSON提取器
- 【JMeter系列-5】JMeter操作Mysql数据库
- 【JMeter系列-6】JMeter BeanShell Sampler与JMeter BeanShell断言
- 【JMeter系列-7】Linux下执行测试
- 【JMeter系列-8】JMeter自定义日志与日志分析
- 【JMeter系列-9】 JMeter常用内置对象