周赛-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/Others)
Total Submission(s): 2813 Accepted Submission(s): 935
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
简单题,注意细节
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <algorithm>
#define LL long long
#define RR freopen("output.txt","r",stdoin)
#define WW freopen("input.txt","w",stdout)
using namespace std;
const int MAX = 100100;
int main()
{
int T;
int n,a,m;
int flag;
int w=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
flag=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a);
if(flag)
{
continue;
}
if(i==0)
{
m=a+1;
}
else
{
if(m==a)
{
m++;
}
else
{
flag=i+1;
}
}
}
printf("Case #%d: ",w++);
if(flag)
{
printf("%d\n",flag);
}
else
{
printf("1\n");
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
周赛-The Number Off of FFF 分类: 比赛 2015-08-02 09:27 3人阅读 评论(0) 收藏的更多相关文章
- Retinex系列之McCann99 Retinex 分类: 图像处理 Matlab 2014-12-03 11:27 585人阅读 评论(0) 收藏
一.McCann99 Retinex McCann99利用金字塔模型建立对图像的多分辨率描述,自顶向下逐层迭代,提高增强效率.对输入图像的长宽有 严格的限制,要求可表示成 ,且 ,. 上述限制来源于金 ...
- 随机L系统分形树 分类: 计算机图形学 2014-06-01 23:27 376人阅读 评论(0) 收藏
下面代码需要插入到MFC项目中运行,实现了计算机图形学中的L系统分形树. class Node { public: int x,y; double direction; Node(){} }; CSt ...
- Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- PIGS 分类: POJ 图论 2015-08-10 09:15 3人阅读 评论(0) 收藏
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18209 Accepted: 8277 Description Mir ...
- Poj 2528 Mayor's posters 分类: Brush Mode 2014-07-23 09:12 84人阅读 评论(0) 收藏
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40570 Accepted: 11798 ...
- Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
- iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏
youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...
- Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏
效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏
using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...
随机推荐
- java 笔记(2) —— 内部类的作用
一.内部类简介 个人觉得内部类没多少研究价值,GUI中的事件响应算是非常典型的应用了. Java内部类其实在J2EE编程中使用较少,不过在窗口应用编程中特别常见,主要用来事件的处理.其实,做非GUI编 ...
- J2EE MyBatis使用
MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis .20 ...
- Tomcat 部署:工程下 META-INF 目录下的 Context.xml
tomcat 在META-INF 文件夹中添加context.xml,使项目自动应用更新文件 Meta-inf文件夹下新建context.xml. <Context path="/FU ...
- 如何抠PSD素材中的图片
在网上经常可以找到一些好看呢的PSD素材,如何才能将这些素材抠出来 存成一张张的png图片呢? 在PhotoShop中 1·隐藏无用的图层,然后窗口中仅剩需要看到的那个素材图 2·用工具选择该区域(注 ...
- 双端队列(单调队列)poj2823 区间最小值(RMQ也可以)
Sliding Window Time Limit: 12000MS Memory Limit: 65536K Total Submissions: 41844 Accepted: 12384 ...
- php4.3.4.4、apache2.0.4.8、mysql 4.0.26、window7 配置过程
apache的安装不需要过程,直接默认安装,下一步 下一步就Ok了. php4的安装: 1 将php-4.0.4-Win32.zip(最新版本4.0.4)解压缩到硬盘的一个目录中,例如解压到E:php ...
- ajax常用参数
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址.前台跳转到后台 请求参数:前台向后台传数据 回调函数:回调函数就是一个自定义的函数在发生特定的事件的时候调用来处理这个事件 ...
- Spring 中 Xml配置文件属性的说明
Xml配置文件属性的说明: <bean id="TheAction" ⑴ class="net.xiaxin.spring.qs.UpperAction" ...
- PHP的几个常用加密函数(转载 https://jellybool.com/post/php-encrypt-functions)
PHP的几个常用加密函数 在网站的开发过程中,常常需要对部分数据(如用户密码)进行加密,本文主要介绍PHP的几个常见的加密函数 MD5加密: string md5 ( string $str [, b ...
- zw版【转发·台湾nvp系列Delphi例程】CheckDifference1
zw版[转发·台湾nvp系列Delphi例程]CheckDifference1 procedure TForm1.Button1Click(Sender: TObject);var img, img1 ...