CF_402B 想法题
题目链接:http://codeforces.com/problemset/problem/402/B
/**算法分析: 题意太大意,positive没注意这个问题 考察等差数列,由An=A1+(n-1)*k,k已知,能够求出A1,找出最大的A1的个数就可以了 */ #include<bits/stdc++.h> #define MAXN 1050 #define PI acos(-1.0) #define REP(i,n) for(int i=0; i<n; i++) #define FOR(i,s,t) for(int i=s; i<=t; i++) #define show(x) { cerr<<">>>"<<#x<<" = "<<x<<endl; } #define showtwo(x,y) { cerr<<">>>"<<#x<<"="<<x<<" "<<#y<<" = "<<y<<endl; } using namespace std; int main() { //freopen("E:\\acm\\input.txt","r",stdin); int n,k; cin>>n>>k; int a[MAXN]; map<int,int> G; int ans=0,mx = 0; FOR(i,1,n) { cin>>a[i]; int tmp = a[i] - (i-1)*k; if(tmp <= 0) continue; G[tmp]++; if(ans < G[tmp]) ans = G[tmp], mx = tmp; } cout<<n - ans<<endl; FOR(i,1,n) { int tmp = mx + (i-1)*k; if(tmp > a[i]) printf("+ %d %d\n",i,tmp-a[i]); else if(tmp < a[i]) printf("- %d %d\n",i,a[i]-tmp); } }