ZOJ1045
2016-01-04 19:34
267 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1045
第一感觉,二分。因为不知道上限是多少,就试一下5.2需要多少长卡片,276张,于是用276作为上限来二分(这么少直接暴力就可以的>_<!)
第一感觉,二分。因为不知道上限是多少,就试一下5.2需要多少长卡片,276张,于是用276作为上限来二分(这么少直接暴力就可以的>_<!)
#include<iostream> #include<cstdio> using namespace std; bool OK(int n,float length) { float sum = 0; for (int i=1; i<=n; i++) { sum += 1.0/(i+1); if (sum >= length) return true; } return false; } int main() { float length; while (cin>>length && length != 0) { int head = 1, tail = 277; int mid,ans; while (head<tail) { mid = (head+tail)>>1; if (OK(mid,length)) { ans = mid; tail = mid; } else head = mid+1; } cout<<ans<<" card(s)"<<endl; } return 0; }
相关文章推荐
- 杀掉YARN上面的SparkSubmit任务
- Pairing heap
- cocos2d-x 3.0 正式版 项目创建
- 朴素贝叶斯
- JS/React 判断对象是否为空对象
- Java并发编程之CountDownLatch
- POJ-1953 World Cup Noise(线性动规)
- eMMC当中HPI的作用以及使用方法
- POJ-1953 World Cup Noise(线性动规)
- 转【实战体验几种MySQLCluster方案】
- 弱菜之快速排序实现,表示因为书上的看不懂只能自己写
- java js 日期总结
- spark-submit工具参数说明
- 亲耳聆听机器人发声
- javaEmail发送邮件问题总结
- 文件与外部排序
- (IOS自学)常见的UNIX指令
- MySql 1067错误
- 数据库基础
- 蓝懿IOS委托模式代理模式