HDU - 4422 The Little Girl who Picks Mushrooms(数学)
2017-07-24 21:04
183 查看
点击打开题目链接
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2885 Accepted Submission(s): 937
Problem Description
It's yet another festival season in Gensokyo. Little girl Alice planned to pick mushrooms in five mountains. She brought five bags with her and used different bags to collect mushrooms from different mountains. Each bag has a capacity of 2012 grams. Alice has
finished picking mushrooms in 0 ≤ n ≤ 5 mountains. In the i-th mountain, she picked 0 ≤ wi ≤ 2012 grams of mushrooms. Now she is moving forward to the remained mountains. After finishing picking mushrooms in all the five mountains, she want to bring
as much mushrooms as possible home to cook a delicious soup.
Alice lives in the forest of magic. At the entry of the forest of magic, live three mischievous fairies, Sunny, Lunar and Star. On Alice's way back home, to enter the forest, she must give them exactly three bags of mushrooms whose total weight must be of integral
kilograms. If she cannot do so, she must leave all the five bags and enter the forest with no mushrooms.
Somewhere in the forest of magic near Alice's house, lives a magician, Marisa. Marisa will steal 1 kilogram of mushrooms repeatedly from Alice until she has no more than 1 kilogram mushrooms in total. So when Alice gets home, what's the maximum possible amount
of mushrooms Alice has? Remember that our common sense doesn't always hold in Gensokyo. People in Gensokyo believe that 1 kilogram is equal to 1024 grams.
Input
There are about 8192 test cases. Proceed to the end of file.
The first line of each test case contains an integer 0 ≤ n ≤ 5, the number of mountains where Alice has picked mushrooms. The second line contains n integers 0 ≤ wi ≤ 2012, the amount of mushrooms picked in each mountain.
Output
For each test case, output the maximum possible amount of mushrooms Alice can bring home, modulo 20121014 (this is NOT a prime).
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
Hint
In the second sample, if Alice doesn't pick any mushrooms from the 5-th mountain. She can give (512+512+0) =1024 grams of mushrooms to Sunny, Lunar and
Star. Marisa won't steal any mushrooms from her as she has exactly 1 kilogram of mushrooms in total.
In the third sample, there are no three bags whose total weight is of integral kilograms. So Alice must leave all the five bags and enter the forest with no mushrooms.
In the last sample:
1.Giving Sunny, Lunar and Star: (208+308+508)=1024
2.Stolen by Marisa: ((708+1108)-1024)=792
Source
2012 Asia ChangChun Regional Contest
Recommend
zhuyuanchen520 | We have carefully selected several similar problems for you: 6032 6031 6030 6029 6028
Statistic | Submit | Discuss | Note
题目大意:一共5座山,Alice拿着5个篮子去采蘑菇,给出Alice已经采过的山和采的数量,求最多可以带多少蘑菇回家。中途有三个不知道什么玩意的东西,他需要给那三个东西每人一袋蘑菇(可为空),使这三袋蘑菇和为1024整数倍。如果没有这样的三袋,则需要把5袋全给出去。之后还会有一个东西,如果他剩余蘑菇总数超过1024,则需要不断给那个东西1024克,直到他所有蘑菇和小于等于1024为止。
思路:没有读出题目给出的为已经采的山和蘑菇数,以为是所有的。所以第一个样例百思不得姐。题意懂了,再分类讨论就可以了。
附上AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int amo[6];
int n;
int sum;
int tmp;
int ans;
int flag;
void init(){
memset(amo,0,sizeof(amo));
sum=0;
tmp=0;
ans=0;
flag=0;
}
int main(){
ios::sync_with_stdio(false);
while(cin>>n){
init();
for(int i=0;i<n;i++){
cin>>amo[i];
sum+=amo[i];
}
if(n<=3){
cout<<"1024"<<endl;
continue;
}
else if(n==4){
for(int i=0;i<4;i++){
if((sum-amo[i])%1024==0){
flag=1;
break;
}
}
if(flag)cout<<"1024"<<endl;
else {
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
tmp=amo[i]+amo[j];
while(tmp>1024)tmp-=1024;
ans=max(ans,tmp);
}
}
cout<<ans<<endl;
}
}
else {
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
if((sum-amo[i]-amo[j])%1024==0){
flag=1;
tmp=amo[i]+amo[j];
while(tmp>1024)tmp-=1024;
ans=max(ans,tmp);
}
}
}
if(flag)cout<<ans<<endl;
else cout<<0<<endl;
}
}
return 0;
}
The Little Girl who Picks Mushrooms
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2885 Accepted Submission(s): 937
Problem Description
It's yet another festival season in Gensokyo. Little girl Alice planned to pick mushrooms in five mountains. She brought five bags with her and used different bags to collect mushrooms from different mountains. Each bag has a capacity of 2012 grams. Alice has
finished picking mushrooms in 0 ≤ n ≤ 5 mountains. In the i-th mountain, she picked 0 ≤ wi ≤ 2012 grams of mushrooms. Now she is moving forward to the remained mountains. After finishing picking mushrooms in all the five mountains, she want to bring
as much mushrooms as possible home to cook a delicious soup.
Alice lives in the forest of magic. At the entry of the forest of magic, live three mischievous fairies, Sunny, Lunar and Star. On Alice's way back home, to enter the forest, she must give them exactly three bags of mushrooms whose total weight must be of integral
kilograms. If she cannot do so, she must leave all the five bags and enter the forest with no mushrooms.
Somewhere in the forest of magic near Alice's house, lives a magician, Marisa. Marisa will steal 1 kilogram of mushrooms repeatedly from Alice until she has no more than 1 kilogram mushrooms in total. So when Alice gets home, what's the maximum possible amount
of mushrooms Alice has? Remember that our common sense doesn't always hold in Gensokyo. People in Gensokyo believe that 1 kilogram is equal to 1024 grams.
Input
There are about 8192 test cases. Proceed to the end of file.
The first line of each test case contains an integer 0 ≤ n ≤ 5, the number of mountains where Alice has picked mushrooms. The second line contains n integers 0 ≤ wi ≤ 2012, the amount of mushrooms picked in each mountain.
Output
For each test case, output the maximum possible amount of mushrooms Alice can bring home, modulo 20121014 (this is NOT a prime).
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
Hint
In the second sample, if Alice doesn't pick any mushrooms from the 5-th mountain. She can give (512+512+0) =1024 grams of mushrooms to Sunny, Lunar and
Star. Marisa won't steal any mushrooms from her as she has exactly 1 kilogram of mushrooms in total.
In the third sample, there are no three bags whose total weight is of integral kilograms. So Alice must leave all the five bags and enter the forest with no mushrooms.
In the last sample:
1.Giving Sunny, Lunar and Star: (208+308+508)=1024
2.Stolen by Marisa: ((708+1108)-1024)=792
Source
2012 Asia ChangChun Regional Contest
Recommend
zhuyuanchen520 | We have carefully selected several similar problems for you: 6032 6031 6030 6029 6028
Statistic | Submit | Discuss | Note
题目大意:一共5座山,Alice拿着5个篮子去采蘑菇,给出Alice已经采过的山和采的数量,求最多可以带多少蘑菇回家。中途有三个不知道什么玩意的东西,他需要给那三个东西每人一袋蘑菇(可为空),使这三袋蘑菇和为1024整数倍。如果没有这样的三袋,则需要把5袋全给出去。之后还会有一个东西,如果他剩余蘑菇总数超过1024,则需要不断给那个东西1024克,直到他所有蘑菇和小于等于1024为止。
思路:没有读出题目给出的为已经采的山和蘑菇数,以为是所有的。所以第一个样例百思不得姐。题意懂了,再分类讨论就可以了。
附上AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int amo[6];
int n;
int sum;
int tmp;
int ans;
int flag;
void init(){
memset(amo,0,sizeof(amo));
sum=0;
tmp=0;
ans=0;
flag=0;
}
int main(){
ios::sync_with_stdio(false);
while(cin>>n){
init();
for(int i=0;i<n;i++){
cin>>amo[i];
sum+=amo[i];
}
if(n<=3){
cout<<"1024"<<endl;
continue;
}
else if(n==4){
for(int i=0;i<4;i++){
if((sum-amo[i])%1024==0){
flag=1;
break;
}
}
if(flag)cout<<"1024"<<endl;
else {
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
tmp=amo[i]+amo[j];
while(tmp>1024)tmp-=1024;
ans=max(ans,tmp);
}
}
cout<<ans<<endl;
}
}
else {
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
if((sum-amo[i]-amo[j])%1024==0){
flag=1;
tmp=amo[i]+amo[j];
while(tmp>1024)tmp-=1024;
ans=max(ans,tmp);
}
}
}
if(flag)cout<<ans<<endl;
else cout<<0<<endl;
}
}
return 0;
}
相关文章推荐
- HDU 2620 - Ice Rain (数学)
- HDU 2289 Cup 数学+二分
- [斐波那契循环节 数学技巧] HDU 3977 Evil teacher
- hdu 1085 Holding Bin-Laden Captive!(多重背包or数学)
- hdu 5276 钟表 (暴力+数学 )
- hdu 1221 数学题
- hdu 5626 数学题
- hdu-4535-吉哥系列故事——礼尚往来-组合数学-错排-java
- 数学,期望(Balls and Boxes,HDU 5810)
- HDU 1061 Rightmost Digit (数学&三种解法)
- HDU 4565 (数学推导 矩阵快速幂)
- 多校6 HDU-6097 Mindis 几何数学
- HDU 4465 Candy ( 数学期望 )
- HDU-5873-Football Games-数学推导
- HDU 1999 数学题
- HDU 4405 Aeroplane chess(概率dp,数学期望)
- HDU 5175 Misaki's Kiss again(数学 最大公约数 异或运算)——BestCoder Valentine's Day Round
- HDU 5584 LCM Walk 数学
- hdu 1491 Octorber 21st(数学题)
- hdu 5184(数学-卡特兰数)