hdu4727题意很难搞懂

 

The Number Off of FFF

 

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 <= 10 5) 
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.

 

题意引申:有N个人在一起报数,本来是从1 ....N, 到有一个人报错了。现在从这N个人中选出n个人,3<=n<=10^5;

这n各种中保证有一个是报错的,要你求出这个人在n个数中的第几个的位置;

 

 

因为是从左往右报数,就是从小的往大的报数,所以当前位置的数若减去前面的数的差不为一,那么错误的肯定是这个数,因为判断是从小的到大的,前面的是已经判断的,肯定是正确的;如果这n个数都符合要求,根据题意一定有一个是错的,那么第一个肯定是错的

 

 

#include <bits/stdc++.h>
using namespace std;



#define pi acos(-1)
#define endl '\n'
#define me(x) memset(x,0,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,-1,-1,1,1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
const int maxn=1e3+5;
const int maxx=1e6+100;
const double EPS=1e-7;
const int mod=1000000007;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
long long gcd(long long a , long long b){if(b==0) return a;a%=b;return gcd(b,a);}


LL ans[100005];
int main()
{
    int t;
    scanf("%d", &t);
    for(int cnt = 1; cnt <= t; cnt++)
    {
        me(ans);
        LL n;
        scanf("%lld", &n);
        for(int i = 0; i < n; i++)
        {
            scanf("%lld", &ans[i]);
        }
        int res;
        int flag = 1;
        for(int i = 0; i < n - 1; i++)
        {
            if(ans[i + 1] - ans[i] != 1)
            {
                flag = 0;
                res = i + 1;
                break;
            }
        }
        if(flag)
            printf("Case #%d: 1\n", cnt);
        else
            printf("Case #%d: %d\n", cnt, res + 1);

    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值