HDOJ1085
来源:互联网 发布:淘宝中推广方法有哪些 编辑:程序博客网 时间:2024/06/18 02:06
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18700 Accepted Submission(s): 8327
Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
“Oh, God! How terrible! ”
![](http://acm.hdu.edu.cn/data/images/1085_1.jpg)
Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
“Oh, God! How terrible! ”
![](http://acm.hdu.edu.cn/data/images/1085_1.jpg)
Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
Sample Input
1 1 30 0 0
Sample Output
4
题意:输入分别有多少个1、2、5,找x系数为0时,对应的最小指数。
G(x)=(1+x+x^2+..)(1+x^2...)(1+x^5+..) 由3个表达式构成,直接展开求解即可。
之前c1[1000]开小了,导致一直显示超时,其实不是超时的原因。如果你前面几个测试用例算的都是正确的,然后后面的算了半天还没算出结果就已经超过规定时间了,但其实就算再给你时间你算出来也是错的 这样的情形下,也是Time Limit Exceeded
再比如,你前面的测试用例算出来都是正确,后面的某个测试用例输入后你就死循环了,把时间全都耗光在某一个测试用例里了,那么你也是超时(Time Limit Exceeded),但实际上你的算法还是错的,给你无限的时间你也算不出结果
#include<stdio.h> using namespace std;int c1[10000],c2[10000];int main(void){int a,b,c;while (scanf("%d %d %d",&a,&b,&c)!=EOF&&(a||b||c)){ int _max=a+2*b+5*c;for(int i=0;i<=_max;i++){c1[i]=0;c2[i]=0;}for(int i=0;i<=a;i++)//第一个表达式 {c1[i]=1;}for(int j=0;j<=a;j++) //第一项乘第二项 {for(int k=0;k<=b*2;k+=2){c2[j+k]+=c1[j];}}for(int q=0;q<=a+2*b;q++)//归并同类项 {c1[q]=c2[q];c2[q]=0;}for(int j=0;j<=a+2*b;j++) //接着乘第三项 {for(int k=0;k<=c*5;k+=5){c2[j+k]+=c1[j];}}for(int q=0;q<=_max ;q++)//归并同类项 {c1[q]=c2[q];c2[q]=0;}int i; for(i=0; i<=_max; ++i) if(c1[i] == 0) { printf("%d\n", i); break; } if(i == _max+1) printf("%d\n", i);}return 0;}
0 0
- hdoj1085
- HDOJ1085
- HDOJ1085
- HDOJ1085母函数的应用
- hdoj1085 Holding Bin-Laden Captive!(又见母函数)
- 异步校验用户名的实现
- 文章标题
- 飞思卡尔IMX6修改uboot默认启动参数
- ubuntu16.04 安装apache php5 mysql & 相关设置
- c++迭代器介绍
- HDOJ1085
- Codevs 1158 尼克的任务
- java中对象与字节数组相互转换
- .java文件突然报错,且无法新建项目
- 约束函数和目标函数带绝对值号的特殊非线性规划问题的求解
- EventBus源码解析
- foreach语句
- 设计模式-行为型- 解释器模式(Interpreter)
- Visual Stdio C++ 编译器 编译 (GSL) GNU Scientific Library 的方法介绍(1)