• 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 }
  • 相关阅读:
    uip源码剖析【三】——【网络层】ICMP解读
    uip源码剖析【五】——【传输层】TCP解读
    WebGame方案汇总
    终于,我生命中第一次编译并运行了手机程序
    使用R7版NDK搭建Android开发环境[不使用Cgywin]
    拷问Unity:开发U3D游戏要思考的问题
    浏览器缓存导致FLASH资源更新问题的解决方案
    山寨版的《KingdomRush(皇城突袭)》
    在Unity3D的网络游戏中实现资源动态加载
    Unity3d之无缝地形场景切换–解决方法和代码
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3315075.html
Copyright © 2020-2023  润新知