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=,mx = ;
FOR(i,,n)
{
cin>>a[i];
int tmp = a[i] - (i-)*k;
if(tmp <= ) continue;
G[tmp]++;
if(ans < G[tmp]) ans = G[tmp], mx = tmp;
}
cout<<n - ans<<endl;
FOR(i,,n)
{
int tmp = mx + (i-)*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);
}
}
上一篇:Firemonkey的旁门左道[六]


下一篇:调试时a标签禁止跳转方法