其实,我只想说这道题好坑~~
不过也怪自己陷进去了,哎~悲剧啊!
其实这道题就是一个简单的模拟题,唯一需要注意的就是0%1204==0 ,1024%1024==0,这里特判一下就好,然后就是那个奇耻无比的坑,他说前三个要3个包加起来是千克的整数倍,也就是1024的整数倍,那么0也算!!!!3个0也可以过这关!!!坑啊!!!
其他的就简单了
The Little Girl who Picks Mushrooms
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description
![Download as PDF Download as PDF](https://icpcarchive.ecs.baylor.edu/components/com_onlinejudge/images/button_pdf.png)
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 0n
5 mountains. In the 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, lives 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 get 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 belive that 1 kilograms is equal to 1024 grams.
Input
There are about 8192 test cases. Process to the end of file.
The first line of each test case contains an integer 0n
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).
Note
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 kilograms 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:
- Giving Sunny, Lunar and Star: (208+308+508)=1024
- Stolen by Marisa: ((708+1108)-1024)=792
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
int n;
int a[10];
int main( )
{
while( scanf("%d",&n) == 1 ){
int sum = 0;
for( int i=1 ; i<=n ; i++ ){
scanf("%d",&a[i]);
sum += a[i];
}
int ans = 0;
bool flag = true;
if( n <= 3 )
ans = 1024;
else if( n == 4 ){
for( int i=1 ; i<=n ; i++ )
if( ((sum - a[i])%1024 == 0) ){
ans = 1024;
flag = false;
break;
}
if( flag ){
for( int i=1 ; i<=n ; i++ )
for( int j=i+1 ; j<=n ; j++ ){
if( ((a[i]+a[j])%1024==0) && (a[i]+a[j]!=0) )
ans = 1024;
ans = max( ans , (a[i]+a[j])%1024 );
}
}
}
else if( n == 5 ){
for( int i=1 ; i<=n ; i++ ){
for( int j=i+1 ; j<=n ; j++ ){
for( int k=j+1 ; k<=n ; k++ ){
if( ((a[i]+a[j]+a[k]) % 1024 == 0) ){
int tmp = 0;
for( int w=1 ; w<=n ; w++ ){
if( w!=i && w!=j && w!=k )
tmp += a[w];
}
flag = false;
if( (tmp != 0) && (tmp%1024==0) )
ans = 1024;
ans = max( ans , tmp%1024 );
}
}
}
}
if( flag )
ans = 0;
}
printf("%d\n",ans%20121014);
}
return 0;
}