The Number Off of FFF

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 602 Accepted Submission(s): 284

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 <= 10
5)

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
 
  1. import java.io.*;
  2. import java.math.BigInteger;
  3. import java.util.*;
  4. public class Main {
  5. int t,n;
  6. long[] a;
  7. public static void main(String[] args) throws IOException{
  8. new Main().work();
  9. }
  10. void work() throws IOException{
  11. BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
  12. PrintWriter pw=new PrintWriter(new OutputStreamWriter(System.out),true);
  13. t=Integer.parseInt(bu.readLine());
  14.  
  15. for(int p=1;p<=t;p++){
  16. pw.print("Case #"+p+": ");
  17. n=Integer.parseInt(bu.readLine());
  18. a=new long[n];
  19. String str[]=bu.readLine().split(" ");
  20. for(int i=0;i<n;i++){
  21. a[i]=Long.parseLong(str[i]);
  22. }
  23.  
  24. long i=a[0];
  25. boolean boo=true;
  26.  
  27. for(int j=0;j<n;j++,i++){
  28. if(i!=a[j]){
  29. pw.println(j+1);
  30. boo=false;
  31. break;
  32. }
  33. }
  34. if(boo)
  35. pw.println(1);
  36. }
  37. }
  38. }

HDU 4727 The Number Off of FFF的更多相关文章

  1. 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 ...

  2. HDU 4727 The Number Off of FFF 2013年四川省赛题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4727 题目大意:队列里所有人进行报数,要找出报错的那个人 思路:,只要找出序列中与钱一个人的数字差不是 ...

  3. 水题 HDOJ 4727 The Number Off of FFF

    题目传送门 /* 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 */ #include <cstdio> #include <iostream> ...

  4. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  5. 周赛-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 ...

  6. hdu 2665 Kth number

    划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...

  7. hdu 4670 Cube number on a tree(点分治)

    Cube number on a tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

  8. 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )

    在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...

  9. 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 ...

随机推荐

  1. Android 实现GIF播放(解码)

    实现原理很简单,先把GIF动画解码成多张Bitmap图片,然后放到AnimationDrawable里面去逐一播放即可. GifHelper代码: package com.android.view; ...

  2. [LeetCode]题解(python):141-Linked List Cycle

    题目来源: https://leetcode.com/problems/linked-list-cycle/ 题意分析: 给定一个链表,判断链表是否有环.要求O(1)空间时间复杂度. 题目思路: 用快 ...

  3. Clear all username or password for login.

    Open cmd.exe In command, type in: control keymgr.dll. This is go to watch the password which you rem ...

  4. MySQL 创建用户与修改密码

    创建用户的 3 方法: 1 .create user userName identifed by 'yourPassword'; 2. grant select on *.* to userName@ ...

  5. JAVA泛型接口

    事例代码: package com.xt.thins_15_3; import java.util.Iterator; /** * 泛型接口 * * @author xue * * @param &l ...

  6. Python GUI编程各种实现的对比

    Python GUI编程各种实现的对比 从 Python 语言的诞生之日起,就有许多优秀的 GUI 工具集整合到 Python 当中,这些优秀的 GUI 工具集,使得 Python 也可以在图形界面编 ...

  7. Java Native Interface Specification(JNI)

    Java Native Interface Specification(JNI) 使用场景: 需要的功能,标准的java不能提供 有了一个用其他的语言写好的工具包,希望用java去访问它 当需要高性能 ...

  8. Android实现 ScrollView + ListView无滚动条滚动

    Android实现 ScrollView+ListView无滚动条滚动,即ListView的数据会全部显示完,但Listview无滚动条. 核心代码如下: 1. NoScrollListView.ja ...

  9. Velocity入门系列

    Velocity介绍 Velocity是一个java模板引擎,通过简洁的语法可以返回动态内容给浏览器使用,本系类是基于velocity官方文档(就是照着翻译,同时对不清楚的地方进行详细讲解),其实技术 ...

  10. C#高级编程技术复习一

    从基本的Socket编程进入 (注意:这是转的一篇2011年的文章,有些知识可能该更新了!) 这一篇文章,我将图文并茂地介绍Socket编程的基础知识,我相信,如果你按照步骤做完实验,一定可以对Soc ...