您的位置:首页 > 其它

HDU 4422 The Little Girl who Picks Mushrooms(模拟)

2013-08-26 17:20 483 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4422

这个题目有点意思,比较坑人,但是看懂之后发现很水

题目意思是有五座山,目前去过n个,还有5-n个没去!

然后就可以直接写答案了,如果n<=3那么结果肯定是1024

如果是5那么直接枚举19种情况

如果是4的话也简单,如果这四个有组合为1024的倍数那么结果直接就是1024

如果没有,还是枚举,看第五座和前面哪两座组合得出结果最大!

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#define MAX(a,b) (a>b?a:b)
using namespace std;
int map[10][5]={0,1,2,3,4,0,1,3,2,4,0,1,4,2,3,0,2,3,1,4,0,2,4,1,3,0,3,4,1,2,
1,2,3,0,4,1,2,4,0,3,1,3,4,0,2,2,3,4,0,1};
int n,rec[10];
int main(){
int i,j,k,ans,temp;
bool flag;
while(scanf("%d",&n)!=EOF){
memset(rec,-1,sizeof(rec));
ans=0,flag=false;
for(i=0;i<n;i++)
scanf("%d",&rec[i]);
if(n <= 3){
printf("%d\n",1024);
continue;
}
for(i=0;i<10;i++){
if(rec[map[i][0]]==-1 || rec[map[i][1]]==-1 || rec[map[i][2]]==-1 ||
(rec[map[i][0]]+rec[map[i][1]]+rec[map[i][2]])%1024==0){
if(rec[map[i][3]]==-1 || rec[map[i][4]]==-1){
ans=1024;
break;
}
else{
temp=rec[map[i][3]]+rec[map[i][4]];
while(temp>1024) temp-=1024;
ans=MAX(ans,temp);
}
}
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HDU 模拟