| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
C++ AC代码(没想明白为什么不按重心解?)#include <iostream>
#include<vector>
#include<map>
#include <stdlib.h>
using namespace std;
int main(void)
{
float c=0;
vector<float>vi;
while (cin >> c){
if (c == 0.00) break;
vi.push_back(c);
}
map<int,float>hangoverTable; //总伸出长度表1/2,1/2+1/3,...调和级数没有通项公式
map<int, float>::iterator it;
hangoverTable[0] = 0;
for (int n = 1; n <= 300; n++){ //最大300张
hangoverTable[n] = hangoverTable[n-1]+1.0 / (n + 1);
}
for (int i = 0; i < vi.size(); i++)
for (it =hangoverTable.begin();it != hangoverTable.end(); it++)
if ((vi[i]- it->second) < 0.001){ //精度0.001
cout << it->first << " card(s)" << endl;
break;
}
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator