周赛-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 ...
随机推荐
- Troubleshooting JDK
收集整理下JDK自带的关于 Troubleshooting 的文档 Java 2 Platform, Standard Edition 5.0 Troubleshooting and Diagnost ...
- sqlserver中索引优化
背景: MRO表中TimeStamp nvarchar(32),但实际上它存储的内容是日期(2015-09-09 11:20:30). 现在我要执行这样一个sql语句: Select t10.* fr ...
- Leetcode: Data Stream as Disjoint Intervals && Summary of TreeMap
Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...
- struts2 标签字体大小
<style type="text/css"> label{ font-size: 20px; } </style> <s:textfield nam ...
- jetbrains公司全系列软件最简单破解教程
由于最新jetbrains发布了IntelliJ IDEA 15. PyCharm 5.PhpStorm10.WebStorm 11.RubyMine等各个版本,但是改变了注册方法.原先的注册码包括注 ...
- Java里的File I/O
Java的输入流主要由:InputStream和Reader作为基类,把持久化数据读入内存.输出流由OutputStream和Write类作为父类. 其中读如内存的时候,不可能一下去全读进去,需要一个 ...
- cometd使用-bayeux协议(读法:贝叶)
bayeux.createChannelIfAbsent("/**", new ServerChannel.Initializer() { @Override public voi ...
- -Xloggc:log/gc.log 指定GC log的位置
-Xloggc:log/gc.log指定GC log的位置,以文件输出帮助开发人员分析问题
- 夺命雷公狗---node.js---14之DNS
node下如果想域名解析是需要通过apache或者ng的反向版定才可以实现的,但是他也给我们留下了哟套DNS操作方法: /** * Created by leigood on 2016/8/30. * ...
- android studio1.0 for Mac环境搭建与demo运行(手动下载gradle,科学上google) 转载
http://blog.csdn.net/allenffl/article/details/41957907 官网下载 http://developer.android.com/sdk/install ...