首页 > 其他 > 详细

Gym - 101670A Amusement Anticipation(CTU Open Contest 2017 签到题)

时间:2018-11-02 23:22:15      阅读:253      评论:0      收藏:0      [点我收藏+]

题目&题意:

倒着找处于最后位置的等差数列的开头的位置。

例:

1 5 3 4 5 6

3 4 5 6是等差数列,它的开头的位置是3

PS:

读题真的很重要!!!!多组输入,上来就读错了!!

代码:

技术分享图片
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define FRE() freopen("in.txt","r",stdin)
using namespace std;
typedef long long ll;
const int maxn = 5e3+10;
int dp[maxn][maxn];
int a[maxn];

int main(){
    //FRE();
    int n;
    while(scanf("%d",&n)!=EOF){
        for(int i=1; i<=n; i++){
            scanf("%d",&a[i]);
        }
        int d = a[n] - a[n-1],index = 1,ok = 0;
        for(int i = n-1; i>=0; i--){
            if(a[i+1]-a[i] != d){
                index = i;
                ok = 1;
                break;
            }
        }
        if(ok)
            printf("%d\n",index+1);
        else
            printf("%d\n",index);
    }
    return 0;
}
/*
PutIn:
5
1 2 3 4 5
7
1 2 3 4 5 8 8
3
7 5 2
PutOut:
1
6
2
*/
View Code

Gym - 101670A Amusement Anticipation(CTU Open Contest 2017 签到题)

原文:https://www.cnblogs.com/sykline/p/9898481.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!