Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

C++ AC代码(没想明白为什么不按重心解?)

Posted by freelark at 2016-10-29 14:52:06 on Problem 1003
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator