题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=3003&rd=5858

比较简单。

代码如下:

  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. #define Rate(win, i) ( (double)(win) / (double)(i) * 100)
  9. #define PRECISE 0.000001
  10.  
  11. class WinningRecord
  12. {
  13. public:
  14. vector <int> getBestAndWorst(string games);
  15. };
  16.  
  17. vector <int> WinningRecord::getBestAndWorst(string games)
  18. {
  19. int i;
  20. int best, worst, win;
  21. double bestRate, worstRate, rate;
  22. int length;
  23. vector <int> ans;
  24.  
  25. best = worst = win = 0;
  26. length = games.size();
  27. bestRate = 0;
  28. worstRate = 100;
  29.  
  30. for (i = 0; i < 2; i++) {
  31. if ('W' == games[i]) {
  32. ++win;
  33. }
  34. }
  35.  
  36. for (i = 2; i < length; i++) {
  37. if ('W' == games[i]) {
  38. ++win;
  39. }
  40.  
  41. rate = Rate(win, i+1);
  42. if ( rate - bestRate > PRECISE || abs(bestRate - rate) < PRECISE ) {
  43. bestRate = rate;
  44. best = i + 1;
  45. }
  46.  
  47. if ( worstRate - rate > PRECISE || abs(worstRate - rate) < PRECISE ) {
  48. worstRate = rate;
  49. worst = i + 1;
  50. }
  51. }
  52.  
  53. ans.push_back(best);
  54. ans.push_back(worst);
  55. return ans;
  56. }

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. 猜数字游戏的提示(UVa340)

    题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...

  2. ASP.NET Zero--4.不使用谷歌字体,提升加载速度

    jtable控件样式中会使用到谷歌字体,每次访问都特别慢 1.打开jtable.css文件 [..\MyCompanyName.AbpZeroTemplate.Web\libs\jquery-jtab ...

  3. ScrureCRT访问CentOS时出现乱码的解决办法

    1.  ScrureCRT访问CentOS时,出现乱码. 登陆后,输入日历命令:cal 输出日历带有乱码的结果: 2.  查看当前系统的语言. 输入命令:echo $LANG 输出:zh_CN.UTF ...

  4. GeneXus项目启动

    使用GeneXus产品开发项目时,在开始,有一些属性我会经常改一下.我现在使用的GeneXus版本是GeneXus U3,由于在做手机应用的开发,所以一般使用最新的版本,老外那边差不多两个月会有一个u ...

  5. Am335x u-boot 启动过程中的系统频率配置

    Am335x的时钟结构分为:ADPLLS和ADPLLLJ 1.ADPLLS用来配置Core_CLK,Dispaly_clk,ARM系统CLK(mpu_clk),DDR PLLs_clk 2.ADPLL ...

  6. 2017/11/7 Leetcode 日记

    2017/11/7 Leetcode 日记 669. Trim a Binary Search Tree Given a binary search tree and the lowest and h ...

  7. 看雪论坛 破解exe 看雪CTF2017第一题分析-『CrackMe』-看雪安全论坛

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 逆向 黑客 破解 学习 论坛 『CrackMe』 http://bbs.pediy.co ...

  8. codevs 1102 采药 2005年NOIP全国联赛普及组

    1102 采药 2005年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB gold   题目描述 Description 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最 ...

  9. [JZYZOJ 1288][洛谷 1005] NOIP2007 矩阵取数 dp 高精度

    https://www.luogu.org/problem/show?pid=1005   dp好想,高精度练手题,有点不舒服的是前后取数位置的计算,代码量太少才会写题这么慢,noip之前虽然重点放在 ...

  10. 【最小表示法】BZOJ2882-工艺

    [题目大意] 求一个循环数列的最小表示法. [思路] 最小表示法模板题.之前用SAM做的,MLE了hhhhh戳☆ #include<iostream> #include<cstdio ...