SRM 212 Div II Level Two: WinningRecord,Brute Force
题目来源: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的更多相关文章
- SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意 ...
- SRM 223 Div II Level Two: BlackAndRed,O(N)复杂度
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3457&rd=5869 解答分析:http://comm ...
- SRM 207 Div II Level Two: RegularSeason,字符串操作(sstream),多关键字排序(操作符重载)
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=2866&rd=5853 主要是要对字符串的操作要熟悉,熟 ...
- SRM 219 Div II Level One: WaiterTipping,小心约分
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609&rd=15503 这题目看上去so easy, ...
- SRM 212 Div II Level One: YahtzeeScore
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1692&rd=5858 比较简单. 代码如下: #inc ...
- SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...
- SRM 582 Div II Level One: SemiPerfectSquare
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <ios ...
- SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2
题目来源: http://community.topcoder.com/tc?module=ProblemDetail&rd=15497&pm=12521 这个问题要注意的就是只需要直 ...
- SRM 582 Div II Level Two SpaceWarDiv2
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 #include <iostream> # ...
随机推荐
- Good Bye 2015 F - New Year and Cleaning
F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...
- Python基本语法[二]
Python基本语法 1.定义变量: 代码正文: x= y= z=x+y 代码讲解: 2.判断语句: 代码正文: score= : print("你真棒") print(&qu ...
- Java 中如何计算两个字符串时间之间的时间差?(单位为分钟)
Java 中如何计算两个字符串时间之间的时间差?(单位为分钟) import java.text.DateFormat; import java.text.ParseException; import ...
- Linux (x86) Exploit 开发系列教程之六(绕过ASLR - 第一部分)
转:https://bbs.pediy.com/thread-217390.htm 前提条件: 经典的基于堆栈的缓冲区溢出 虚拟机安装:Ubuntu 12.04(x86) 在以前的帖子中,我们看到了攻 ...
- 去除win7桌面图标小箭头.bat
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" ...
- here with you
Here With You - Asher Book To all my friends对我所有好友来讲The night is young夜未央The music's loud乐未殇They pla ...
- 图形管线之旅 Part6
原文:<A trip through the Graphics Pipeline 2011> 翻译:往昔之剑 转载请注明出处 欢迎回来.这次我们去看看三角形的光栅化.但在光栅化三角 ...
- 图形管线之旅 Part5
原文:<A trip through the Graphics Pipeline 2011> 翻译:往昔之剑 转载请注明出处 在上一篇关于纹理采样器之后,我们现在回到了3D前端.那 ...
- Redis学习篇(十二)之管道技术
通过管道技术降低往返时延 当后一条命令不依赖于前一条命令的返回结果时,可以使用管道技术将多条命令一起 发送给redis服务器,服务器执行结束之后,一起返回结果,降低了通信频度.
- Hibernate 基于外键的双向一对一关联映射
之前简单介绍了基于外键的单项一对一的关联映射关系,本文简单介绍基于外键的双向一对一的关联映射. 1.设计表结构 表结构对于双向一对一来说没有多少改变,只是双向都可以获取到对方. 2.创建Person对 ...