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> # ...
随机推荐
- 【51nod】1227 平均最小公倍数
题解 这个故事告诉们数论函数不要往分式上跑,你推不出来 好久没推式子了这么明显的转化我都忘了= = 首先\(A(n) = \frac{1}{n} \sum_{i = 1}^{n} \frac{i * ...
- ELK系列--问题汇总(二)
1.Kibana4 dashboard无法保存拖动的visualization位置 原因: 程序bug,json部分未能及时保存拖动的情况 解决方法: 手动在设置中,手动编辑dashboard的jso ...
- openssl解析国密X509证书
openssl解析国密X509证书,把公钥拿出来重写一下就行了 x = strToX509(pbCert, pulCertLen);dwRet = getCertPubKey(x, &a ...
- T1,T2,T3 三个线程顺序执行
T1,T2,T3 三个线程顺序执行 现在有 T1.T2.T3 三个线程,你怎样保证 T2 在 T1 执行完后执行,T3 在 T2 执行完后执行?(T1->T2->T3) 这个线程问题通常会 ...
- 路径方案数 [SPFA,拓扑排序]
路径方案数 [题目描述] 给一张无向图,n 个点和 m 条边,cyb 在 1 号点,他要去 2 号点, cyb 可以从 a 走到 b,当且仅当 a 到 2 的最短路,比 b 到 2 的最短路长. 求 ...
- Python并发编程-进程池及异步方式
进程池的基本概念 为什么有进程池的概念 效率问题 每次开启进程,都需要开启属于这个进程的内存空间 寄存器,堆栈 进程过多,操作系统的调度 进程池 python中的 先创建一个属于进程的池子 这个池子指 ...
- 首次使用ideal构建maven项目web
如附件 链接:https://pan.baidu.com/s/1oH-9VfIKnLPjVt-tOH7fZw 提取码:7s5t
- NumPy 新知
import numpy as np a = np.arange(5) a array([0, 1, 2, 3, 4]) 增加一个维度: b = a[:, None] c = a[:,np.newax ...
- Python Socket多线程并发
1.SocketServer模块编写的TCP服务器端代码 Socketserver原理图 服务端: import SocketServer #导入SocketServer,多线程并发由此类实现 cla ...
- java8新特性——方法引用与构造器引用
上篇文章简单学习了java8内置得4大核心函数式接口,这类接口可以解决我们遇到得大多数得业务场景得问题.今天来简单学习一下方法引用与构造器引用. 一.方法引用 方法引用:若lambda 体中得内容已经 ...