题目来源: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;
}

SRM 212 Div II Level Two: WinningRecord,Brute Force的更多相关文章

  1. SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意  ...

  2. SRM 223 Div II Level Two: BlackAndRed,O(N)复杂度

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3457&rd=5869 解答分析:http://comm ...

  3. SRM 207 Div II Level Two: RegularSeason,字符串操作(sstream),多关键字排序(操作符重载)

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=2866&rd=5853 主要是要对字符串的操作要熟悉,熟 ...

  4. SRM 219 Div II Level One: WaiterTipping,小心约分

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609&rd=15503 这题目看上去so easy, ...

  5. SRM 212 Div II Level One: YahtzeeScore

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1692&rd=5858 比较简单. 代码如下: #inc ...

  6. SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...

  7. SRM 582 Div II Level One: SemiPerfectSquare

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <ios ...

  8. SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2

    题目来源: http://community.topcoder.com/tc?module=ProblemDetail&rd=15497&pm=12521 这个问题要注意的就是只需要直 ...

  9. SRM 582 Div II Level Two SpaceWarDiv2

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 #include <iostream> # ...

随机推荐

  1. hdu4796

    4月真是没写啥题,这题还是月初写的…… 不错的插头dp,首先由n和m的范围知肯定是轮廓线是横向划的 问题的难点在于怎么处理下面两个问题 1.怎么处理独立插头 2.怎么处理完全将W和L左右隔开 先说独立 ...

  2. lr_start_transaction/lr_end_transaction事物组合

    lr_start_transaction/lr_end_transaction事物组合 总结一下: lr_start_transaction与lr_end_transaction 为使用最多的事物创造 ...

  3. 洛谷P3834 [模板]可持久化线段树1(主席树) [主席树]

    题目传送门 可持久化线段树1(主席树) 题目背景 这是个非常经典的主席树入门题——静态区间第K小 数据已经过加强,请使用主席树.同时请注意常数优化 题目描述 如题,给定N个正整数构成的序列,将对于指定 ...

  4. Python上下文管理器(context manager)

    上下文管理器(context manager)是Python2.5开始支持的一种语法,用于规定某个对象的使用范围.一旦进入或者离开该使用范围,会有特殊操作被调用 (比如为对象分配或者释放内存).它的语 ...

  5. ACID数据库事务正确执行的四个基本要素的缩写

    ACID,指数据库事务正确执行的四个基本要素的缩写.包含:原子性(Atomicity).一致性(Consistency).隔离性(Isolation).持久性(Durability).一个支持事务(T ...

  6. TCP/IP——IP网络协议简记

    IP提供不可靠.无连接的数据报传送服务 不可靠:不保证IP数据报能成功到达目的地,当发生错误时,IP的做法是丢弃这个数据报,然后发送ICMP消息报给信息源. 无连接:IP不维护任何关于后续数据报的状态 ...

  7. mysql-8.0.12安装和配置

    1.下载Mysql8.0.12压缩包.下载地址:https://dev.mysql.com/downloads/file/?id=480557 2.解压文件到本地指定目录.这里我的mysql根目录是: ...

  8. 【Python】单例模式Singleton

    前两天一个面试被问到python中单例模式有几种实现方式,只答出了可以用元类实现...然后就想不起来了. 之后翻书,原来这些之前都见过的啊.... 1.手动实现真正创建实例的方法__new__()来实 ...

  9. herbinate 数据库乱码

    改jdbc或者hibernate编码:   jdbc:mysql://127.0.0.1:3306/db?useUnicode=true&characterEncoding=utf-8    ...

  10. bzoj 3685: 普通van Emde Boas树

    3685: 普通van Emde Boas树 Description 设计数据结构支持:1 x  若x不存在,插入x2 x  若x存在,删除x3    输出当前最小值,若不存在输出-14    输出当 ...