您的位置:首页 > 其它

SRM 212 Div II Level Two: WinningRecord,Brute Force

2013-07-06 21:06 561 查看
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3003&rd=5858

比较简单。

代码如下:

#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

#define Rate(win, i) ( (double)(win) / (double)(i) * 100)
#define PRECISE 0.000001

class WinningRecord
{
public:
vector <int> getBestAndWorst(string games);
};

vector <int> WinningRecord::getBestAndWorst(string games)
{
int i;
int best, worst, win;
double bestRate, worstRate, rate;
int length;
vector <int> ans;

best = worst = win = 0;
length = games.size();
bestRate = 0;
worstRate = 100;

for (i = 0; i < 2; i++) {
if ('W' == games[i]) {
++win;
}
}

for (i = 2; i < length; i++) {
if ('W' == games[i]) {
++win;
}

rate = Rate(win, i+1);
if ( rate - bestRate > PRECISE || abs(bestRate - rate) < PRECISE ) {
bestRate = rate;
best = i + 1;
}

if ( worstRate - rate > PRECISE || abs(worstRate - rate) < PRECISE ) {
worstRate = rate;
worst = i + 1;
}
}

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