标签:get pat style targe contest none 题目 bit long
倒着找处于最后位置的等差数列的开头的位置。
例:
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 */
Gym - 101670A Amusement Anticipation(CTU Open Contest 2017 签到题)
标签:get pat style targe contest none 题目 bit long
原文地址:https://www.cnblogs.com/sykline/p/9898481.html