周赛-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 ...
随机推荐
- max-min fairness 最大最小公平算法
我们经常面临给一组用户划分稀有资源的问题,他们都享有等价的权利来获取资源,但是其中一些用户实际上只需要比其他用户少的资源.那么我们如何来分配资源呢?一种在实际中广泛使用的分享技术称作“最大最小公平分享 ...
- CSS3 auto revolution practitioner!
1.html <!DOCTYPE html> <html> <head> <title></title> <meta charset= ...
- Java基础(51):Super与this的区别
1. 子类的构造函数如果要引用super的话,必须把super放在函数的首位. class Base { Base() { System.out.println("Base" ...
- poj: 3094
简单题 #include <iostream> #include <stdio.h> #include <string> #include <stack> ...
- php中时间戳和日期格式的转换
一,PHP时间戳函数获取指定日期的unix时间戳 strtotime(”2009-1-22″) 示例如下: echo strtotime(”2009-1-22″) 结果:1232553600 说明:返 ...
- bzoj1834 [ZJOI2010]network 网络扩容
第一问跑最大流,第二问新建一条边连接0和1,流量为上第一问的答案+k,费用为0,接下来图中每条边拆成两条边,第一条容量为C费用为0,第二条容量无穷费用为W,再跑一遍费用流即可. 代码 #include ...
- struts_24_基于XML校验的规则、特点
当为某个action提供了ActionClassName-validation.xml和ActionClassName-ActionName-validation.xml两种规则的校验文件时,系统按下 ...
- paper 57 :颜色直方图的代码
clear clc close all Image = imread('29.jpg');[M,N,O] = size(Image);[h,s,v] = rgb2hsv(Image); H = h; ...
- 夺命雷公狗---DEDECMS----7dedecms目录结构
我们dedecms的目录结构其实只需要一张图即可明了了,如下图所示:
- 《Focus On 3D Terrain Programming》中一段代码的注释一
取自<Focus On 3D Terrain Programming>中的一段: //--------------------------------------------------- ...