您的位置:首页 > 编程语言 > Go语言

[POJ_1003]Hangover

2011-08-23 15:24 344 查看
#include <iostream>
using namespace std;

const int SIZE = 1000;
float table[SIZE];
int cal_size = 1;
int inc = 50;

void build_table_to(int newSize)
{
if (newSize <= cal_size)
return ;

for (int i=cal_size; i<newSize; i++)
{
float t = 1.0f / (float)(i+2);
table[i] = table[i-1] + t;
}

cal_size = newSize;
}

int get_num_pad(float len)
{
float currMaxLen = table[cal_size-1];
while (currMaxLen < len)
{
build_table_to(cal_size + inc);
currMaxLen = table[cal_size-1];
}

for (int i=0; i<cal_size; i++)
{
if (table[i] > len)
return i+1;
}

return -1;
}

int main()
{
table[0] = 0.5f;
build_table_to(50);

float input;
cin >> input;
while ( input > 0.000001f )
{
cout << get_num_pad(input) << " card(s)" << endl;
cin >> input;
}

return 1;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: