zoj 3365 灵活数字规律
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3365
#include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #define maxn 50500 #define maxe 11000 #define INF 0x3f3f3f using namespace std; int a[maxn],b[maxn]; int main(){ //freopen("input.txt","r",stdin); int n; while(scanf("%d",&n) == 1){ for(int i=1;i<=n;i++){ scanf("%d",&a[i]); b[i] = a[i] - i; } sort(b+1,b+n+1); int maxnum,renum; maxnum = 0; for(int i=1;i<=n;i++){ int num = 1; for(int j=i+1;j<=n;j++){ if(b[j] == b[i]) num++; else{ i = j-1; break; } } if(num > maxnum){ // 这个嵌套有问题,导致WA; maxnum = num; renum = b[i]; } } printf("%d\n",n-maxnum); for(int i=1;i<n;i++) printf("%d ",renum+i); printf("%d\n",renum+n); } }