题目链接:http://poj.org/problem?id=2709
解题报告:
#include <stdio.h> #include <algorithm> #include <string.h> using namespace std; bool cmp(int a,int b) { return a>b; } int colors[15]; int main() { int i; int n, g, ans, _max; while(scanf("%d", &n),n) { memset(colors, 0, sizeof(colors)); _max = 0; for(i=0; i<n; i++) { scanf("%d", &colors[i]); if(colors[i] > _max) _max=colors[i]; } scanf("%d",&g); if(_max%50) ans=_max/50+1; else ans=_max/50; for(i=0; i<n; i++) { colors[i]=ans*50-colors[i]; } sort(colors,colors+n,cmp); while(1) { if(colors[2]==0&&g>0) { ans++; for(i=0; i<n; i++) colors[i]+=50; } g--; if(g<= 0) break; else { colors[0]--; colors[1]--; colors[2]--; sort(colors,colors+n,cmp); } } printf("%d ",ans); } return 0; }