日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 4422 The Little Girl who Picks Mushrooms(简单题)

發(fā)布時間:2025/3/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 4422 The Little Girl who Picks Mushrooms(简单题) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=4422

題目大意:小姑娘背著5個包去山上采蘑菇,每座山上只能用一個背包采集。三個小精靈會要她3個背包,其里面蘑菇的數(shù)量必須是1024的倍數(shù),否則5個背包都會被拿走。然后魔術(shù)師會從她剩下的背包里取走蘑菇,每次取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 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/acm-bingzi/p/3355336.html

總結(jié)

以上是生活随笔為你收集整理的HDU 4422 The Little Girl who Picks Mushrooms(简单题)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。