简单题。
注意不要重复计算。
使用二分查找的思想。
AC。
#include <iostream>
#include <map>
using namespace std;
int getCards(map<int, double>&, double);
int binaryChop(map<int, double>&, double, int, int);
int main ()
{
double dLength;
map<int, double> mStdLength;
mStdLength[0] = 0;
while ( cin >> dLength )
{
if (dLength == 0.0)
{
break;
}
cout << getCards(mStdLength, dLength) << " card(s)" << endl;
}
return 0;
}
int getCards(map<int, double>& mStdLength, double dLength)
{
map<int, double>::iterator iterm = mStdLength.end();
if (dLength > (--iterm)->second)
{
int i = iterm->first;
while (1)
{
mStdLength[i + 1] = mStdLength[i] + 1.0 / (i + 2);
if (dLength <= mStdLength[i + 1])
{
return i + 1;
}
else {
i++;
}
}
}
else
{
int i = iterm->first;
binaryChop(mStdLength, dLength, 0, i);
}
}
int binaryChop(map<int, double>& mStdLength, double dLength, int iFirst, int iLast)
{
if (iFirst + 1 == iLast)
{
return iLast;
}
int iMid = (iFirst + iLast)/2;
if (dLength <= mStdLength[iMid])
{
binaryChop(mStdLength, dLength, iFirst, iMid);
}
else if (dLength > mStdLength[iMid])
{
binaryChop(mStdLength, dLength, iMid, iLast);
}
}
分享到:
相关推荐
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
北大POJ1003-Hangover 解题报告+AC代码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
poj 1440解题报告 poj 1440解题报告 poj 1440解题报告 poj 1440解题报告
poj 3083解题报告poj 3083解题报告poj 3083解题报告poj 3083解题报告
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
poj 3720解题报告poj 3720解题报告poj 3720解题报告poj 3720解题报告
poj1691解题报告 题目来源:http://acm.pku.edu.cn/JudgeOnline/showproblem?problem_id=1691(POJ No.1691) 解法: 搜索
poj2828解题报告,希望能帮到志同道合的算法爱好者
北大poj解题报告,希望能帮到软件工程的同学,每天一道,持之以恒,熟能生巧,与您共勉!
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44187 Accepted: 20574 Description How far can you make a stack of cards overhang a table? If you have one card, you can create a...
北大ACM1316解题报告
Problem 1061 青蛙的约会 poj解题报告。有源码。可直接提交C++实现
ACM Poj Pku 解题报告答案 打包 下载 600多题 史上最全 不是网上乱传的200多题,更不是100多题就挂着10分才能下的题 下了这个 大家也不要浪费分数去下载其它版本的了,基本上都有 共享 一起进步 中国加油 ACMer...
这是我发的第二篇解题报告,写的不怎么的。呵呵!!!!!
北大ACM在线评测系统POJ的题目解题报告。涵盖各种类型的acm题目。值得参考借鉴。打包下载。
ACM POJ 解题报告北大POJ 大量解题代码
不错的资源 收集了网上的一些解题报告 方便同学们学习参考