HDU 4422 The Little Girl who Picks Mushrooms(简单题)
生活随笔
收集整理的這篇文章主要介紹了
HDU 4422 The Little Girl who Picks Mushrooms(简单题)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=4422
題目大意:小姑娘背著5個包去山上采蘑菇,每座山上只能用一個背包采集。三個小精靈會要她3個背包,其里面蘑菇的數量必須是1024的倍數,否則5個背包都會被拿走。然后魔術師會從她剩下的背包里取走蘑菇,每次取1024克,直到蘑菇不超過1024克為止。求小姑娘最多能得到多少蘑菇。
Sample Input 1 9 4 512?512?512 512 5 100 200 300 400 500 5 208 308 508 708 1108 Sample Output 1024 1024 0 792代碼如下:
1 # include<stdio.h> 2 # include<algorithm> 3 # include<iostream> 4 using namespace std; 5 6 int n,a[6],sum,ans; 7 8 int calc(int x) 9 { 10 while(x > 1024) 11 x -= 1024; 12 return x; 13 } 14 15 void solve() 16 { 17 for(int i=0; i<n; i++) 18 for(int j=i+1; j<n; j++) 19 if(n==4 || (sum-a[i]-a[j])%1024==0) 20 ans = max(ans,calc(a[i]+a[j])); 21 } 22 23 int main() 24 { 25 while(scanf("%d",&n)!=EOF) 26 { 27 sum = 0,ans = 0; 28 for(int i=0; i<n; i++) 29 { 30 scanf("%d",&a[i]); 31 sum += a[i]; 32 } 33 if(n<=3) 34 ans = 1024; 35 else if(n==4) 36 for(int i=0; i<4; i++) 37 if((sum-a[i])%1024==0) 38 ans = 1024; 39 if(ans!=1024) 40 solve(); 41 printf("%d\n",ans); 42 } 43 return 0; 44 }?
轉載于:https://www.cnblogs.com/acm-bingzi/p/3355336.html
總結
以上是生活随笔為你收集整理的HDU 4422 The Little Girl who Picks Mushrooms(简单题)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Chart.js学习
- 下一篇: ie6 ie7下使用clear不能将浮动