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 }
  • 相关阅读:
    高危预警|RDP漏洞或引发大规模蠕虫爆发,用户可用阿里云免费检测服务自检,建议尽快修复
    高危预警| SQL数据库成主要攻击对象,或引发新一轮大规模勒索
    dp练习(7)—— 最小和
    dp练习(6)——搬运礼物
    dp练习(5)——最长严格上升子序列
    dp练习(4)——过河卒
    dp练习(3)——棋盘问题
    dp练习(2)——老鼠的旅行
    dp练习(1)——马走日字
    埃氏筛法——标记质数
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3315075.html
Copyright © 2011-2022 走看看