• 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 }
  • 相关阅读:
    va_list va_start va_end va_arg 解决变参问题
    标准输出文件
    Qt QDataTime QString 两个类的使用
    联合开发网站
    iOS LLDB调试器和断点调试
    Wireshark 网络抓包工具Wireshark的使用
    linux 操作系统下c语言编程入门
    iOS 应用崩溃日志分析
    iOS sqlite3数据库解析
    iOS 解析手势识别(Gesture Recognizers)
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3315075.html
Copyright © 2020-2023  润新知