ZOJ Problem Set - 3657The Little Girl who Picks Mushrooms
来源:互联网 发布:linux编辑只读文件 编辑:程序博客网 时间:2024/06/05 00:15
The 2012 ACM-ICPC Asia Changchun Regional Contest-C
题目大意就是 5个数要求三个数和为1024,使得(其他两个数的和-1)%1024+1最大。
当n<=3时,答案显然是1024. n==4 先看有无三个数的和是1024的倍数,没有的话,只能靠第5个数构造,然后枚举期中两个数的和 ,取最大答案。
如果n=5 就是直接枚举答案了。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int a[10];int n,ans;int max(int a,int b){return (a<b?b:a);}int main(){ while (cin>>n){ int sum=0; for (int i=0;i<n;++i) scanf("%d",&a[i]),sum+=a[i]; if (n<=3) cout<<1024<<endl; else { if (n==4){ ans=0; for (int i=0;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) ans=1024; for (int i=0;i<n;++i) for (int j=i+1;j<n;++j) ans=max(ans,(sum-a[i]-a[j]-1)%1024+1); } else { ans=0; for (int i=0;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) ans=max(ans,(sum-a[i]-a[j]-a[k]-1)%1024+1); } cout<< ans << endl; } } return 0;}
- ZOJ Problem Set - 3657The Little Girl who Picks Mushrooms
- zoj The Little Girl who Picks Mushrooms
- ZOJ 3657 The Little Girl who Picks Mushrooms
- The Little Girl who Picks Mushrooms
- HDUOJ4422 The Little Girl who Picks Mushrooms
- The Little Girl who Picks Mushrooms
- zoj3657-The Little Girl who Picks Mushrooms
- The Little Girl who Picks Mushrooms HDU
- The Little Girl who Picks Mushrooms(HDU
- The Little Girl who Picks Mushrooms
- The Little Girl who Picks Mushrooms HDU
- ZOJ 3657 The Little Girl who Picks Mushrooms(2012长春现场赛C题)
- ACM->逻辑判断 ZOJ 3657 The Little Girl who Picks Mushrooms
- ZOJ 3657 The Little Girl who Picks Mushrooms(12年长春区域赛-C题-枚举)
- hdu 4422 The Little Girl who Picks Mushrooms
- hdu 4422The Little Girl who Picks Mushrooms
- hdu(4422)The Little Girl who Picks Mushrooms
- hdu 4422 The Little Girl who Picks Mushrooms
- 可折叠成小托车的自行车
- MyEclipse(Java)连接SQLServer 2008 part1
- MEF应用(2)
- 接口封装及调用
- 为你自己找一个导师
- ZOJ Problem Set - 3657The Little Girl who Picks Mushrooms
- 常用的Mac快捷键
- tp-link后门
- 嵌入式程序员C语言测试题
- zend studio常见问题解答 破解
- OpenStack最新版本Folsom架构解析
- android 单选,复选按钮,以及toast
- Google和Microsoft的地图服务--李开复
- 响应式web网站资料收集