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 }
  • 相关阅读:
    小小的蜗牛有大大的梦想
    Spring整合的quartz任务调度的实现方式
    HDU/HDOJ 2612 Find a way 双向BFS
    在静态库中,实现自动的初始化与卸载接口
    CF 316C2(Tidying Up-二分图最大边权)
    Qt线程同步操作用QWaitCondition QMutex
    MQ、JMS以及ActiveMQ
    微博分享利器
    discuz清空session,导致session保存机制失败,session无法更新与解决
    路由器和交换机的综合实验(1)
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3315075.html
Copyright © 2011-2022 走看看