The Little Girl who Picks Mushrooms
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2600 Accepted Submission(s): 828
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.
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 ≤ w i ≤ 2012, the amount of mushrooms picked in each mountain.
1 9 4 512 512 512 512 5 100 200 300 400 500 5 208 308 508 708 1108
1024 1024 0 792HintIn 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
第一次做区域赛的题目
大牛勿笑!!!!
好开心
昨天和大家一起做的时候因为心态不好,总觉得区域赛的题目不是我们这种小白可以去做的
但是今天静下心来仔细看题目,居然一个小时一次性过了,当然也有昨天做的铺垫今天才会这么顺利
题意:
小女孩过五指山
一定会全部走过五座山
每一座山都会采蘑菇,放在一个袋子里面了
然后就刚好五座山放在五个袋子里面
采完之后就回家
回家的途中会被魔法拿去1024的整数倍,并且是三个袋子组合成的(要是没有三个袋子组合成1024的倍数,那么五个袋子都会被拿走)
然后回到家中还会被偷,直到被偷的剩下的不超过1024就不会被偷了
题解:
题目给出的走过的山可以使 0 1 2 3 4 5
当为0 1 2 3的时候,小女孩还可以去另外的山采蘑菇,数目可以是任意的,然后最后的结果可以最大为1024
当为 4 的时候 小女孩还可以去另外的一座山,那么就有两种情况
1:要是其中三个袋子可以组合成1024的倍数,那么最后剩下的最多是1024
2:要是不能,那么就要从其中选两个袋子,然后不断的被偷,直到剩下的不超过1024,排序取最大
当为 5的时候 小女孩只能任意选三个袋子,组合成1024 的倍数,这时候,就会有多种组合的方式,然后计算可以剩下的最多的情况并且输出就好了
注意:
这里被偷的时候不是模1042,而是用一个循环不断的减去1024,直到不大于1024
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
int n;
int a[10];
while(scanf("%d",&n)!=EOF)
{
int sum=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
if(n<=3)
printf("1024\n");
else if(n==5){
int ans[20],pos=0;
for(int i=1;i<=5;i++){
for(int j=i+1;j<=5;j++){
for(int k=j+1;k<=5;k++){
if((a[i]+a[j]+a[k])%1024==0){
ans[pos]=sum-(a[i]+a[j]+a[k]);
while(ans[pos]>1024){
ans[pos]-=1024;
}
pos++;
}
}
}
}
if(pos==0)
printf("0\n");
else{
sort(ans,ans+pos);
printf("%d\n",ans[pos-1]);
}
}
else{
int flag=0;
for(int i=1;i<=4;i++){
for(int j=i+1;j<=4;j++){
for(int k=j+1;k<=4;k++){
if(flag==0&&(a[i]+a[j]+a[k])%1024==0){
flag=1;
printf("1024\n");
}
}
}
}
int ans[20],pos=0;
if(flag==0){
for(int i=1;i<=4;i++){
for(int j=i+1;j<=4;j++){
ans[pos]=a[i]+a[j];
while(ans[pos]>1024){
ans[pos]-=1024;
}
pos++;
}
}
sort(ans,ans+pos);
printf("%d\n",ans[pos-1]);
}
}
}
return 0;
}