zoukankan      html  css  js  c++  java
  • 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/Others)
    Total Submission(s): 78    Accepted Submission(s): 36


    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
     
    Recommend
    zhuyuanchen520
     
     1 /* ***********************************************
     2 Author        :kuangbin
     3 Created Time  :2013-9-11 12:08:15
     4 File Name     :2013-9-111012.cpp
     5 ************************************************ */
     6 
     7 #include <stdio.h>
     8 #include <string.h>
     9 #include <iostream>
    10 #include <algorithm>
    11 #include <vector>
    12 #include <queue>
    13 #include <set>
    14 #include <map>
    15 #include <string>
    16 #include <math.h>
    17 #include <stdlib.h>
    18 #include <time.h>
    19 using namespace std;
    20 int a[100010];
    21 int main()
    22 {
    23     //freopen("in.txt","r",stdin);
    24     //freopen("out.txt","w",stdout);
    25     int T;
    26     int n;
    27     scanf("%d",&T);
    28     int iCase = 0;
    29     while(T--)
    30     {
    31         iCase++;
    32         scanf("%d",&n);
    33         for(int i = 0;i < n;i++)
    34             scanf("%d",&a[i]);
    35         int ans = 1;
    36         for(int i = 1;i < n;i++)
    37             if(a[i] != a[i-1] + 1)
    38             {
    39                 ans = i+1;
    40                 break;
    41             }
    42         printf("Case #%d: %d
    ",iCase,ans);
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    Sencha的Eclipse插件提示和技巧
    《敏捷软件开发过程及最佳实践》培训总结
    《Sencha应用程序的UI测试 》一文的示例分析
    Ext JS 4.2 Beta版发布
    迅速解决resin或者tomcat启动闪一下就消失的问题
    import javax.servlet 出错
    有爱好者把我的CMS管理系统改成了JAVA版,有兴趣的可以看看
    一个@符号引发的血案:Access数据库无法更新
    Windows 7下如何安装和配置IIS 7和ASP
    .Net中Freetextbox_1.6.3的使用与ftb.imagegallery.aspx安全修正
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3315075.html
Copyright © 2011-2022 走看看