标签:
题意:
思路:
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<vector> #include<ctype.h> #define LL __int64 using namespace std; const int MAXN=1000+5; const int INF=0x3f3f3f3f; int a[MAXN],id,n; bool judge(int a[]) { int Minn=INF; for(int i=0;i<n;i++) if(a[i]!=0 && a[i]<Minn) { Minn=a[i]; id=i; } if(Minn==INF) return false; else return true; } int main() { while(scanf("%d",&n)!=EOF) { int minn=INF; for(int i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<minn) minn=a[i]; } int cnt=1; for(int i=0;i<n;i++) a[i]=a[i]-minn; while(judge(a)) { int minnum=a[id]; for(int i=id;i>=0;i--) { if(a[i]==0) break; a[i]=a[i]-minnum; } for(int i=id+1;i<n;i++) { if(a[i]==0) break; a[i]=a[i]-minnum; } cnt++; } printf("%d\n",cnt); } return 0; }
woj 1567 - D - Sloth's Angry(贪心)
标签:
原文地址:http://www.cnblogs.com/sola1994/p/4443931.html