1. 程式人生 > >Gym - 101670A Amusement Anticipation(CTU Open Contest 2017 簽到題)

Gym - 101670A Amusement Anticipation(CTU Open Contest 2017 簽到題)

-a amp define namespace ORC name none its urn

題目&題意:

倒著找處於最後位置的等差數列的開頭的位置。

例:

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 簽到題)