贪心,POJ(2709)
生活随笔
收集整理的這篇文章主要介紹了
贪心,POJ(2709)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目鏈接: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\n",ans);}return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/TreeDream/p/5348206.html
總結(jié)
以上是生活随笔為你收集整理的贪心,POJ(2709)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OWASP-ZAP
- 下一篇: 我理解的--java观察者模式