题目来源: http://community.topcoder.com/tc?module=ProblemDetail&rd=15497&pm=12521

这个问题要注意的就是只需要直接将参数ratings中字符串连接起来就可以, 不用在每个元素后面加空格. 我开

始就以为每个元素连接的时候在后面要加空格分隔, 然后再把重复的元素去掉, 结果system test出错了, 调试半

天不知道什么问题. 而且题目是面也说了, 没有相重复的数据.

由此可见, TopCoder上有些题目看似简单, 其实有坑, 而且一般这样的坑样例测不出来, 然后通过了样例就submit,

system test直接就挂了, 值得一说的是, 这道题目正确率也只有%10.

代码如下:

#include <algorithm>
#include <sstream>
#include <string>
#include <vector> using namespace std; /************** Program Begin *********************/
class EllysRoomAssignmentsDiv2 {
public:
double getProbability(vector <string> ratings) {
double res;
int Elly; string rating = "";
for (int i = 0; i < ratings.size(); i++) {
rating += ratings[i];
} vector <int> regs;
istringstream iss(rating);
int member = 0;
while (iss >> member) {
regs.push_back(member);
} Elly = regs[0]; sort(regs.begin(), regs.end(), greater <int> () ); int pos = 0;
for (int i = 0; i < regs.size(); i++) {
if (Elly == regs[i]) {
pos = i;
break;
}
} int rooms = (regs.size() + 19) / 20; if (0 == pos) {
res = 1.0;
} else if (pos < rooms) {
res = 0.0;
} else {
res = 1.0 / rooms;
} return res;
}
}; /************** Program End ************************/

SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2的更多相关文章

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

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

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

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

  3. SRM 582 Div II Level One: SemiPerfectSquare

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

  4. SRM 582 Div II Level Two SpaceWarDiv2

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

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

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

  6. SRM 583 Div II Level One:SwappingDigits

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

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

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

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

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

  9. SRM 212 Div II Level One: YahtzeeScore

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

随机推荐

  1. BZOJ 1096

    const maxm=1e100; maxn=; ..maxn] of int64; q:..maxn] of longint; n,i,h,t:longint; function calc(j,i: ...

  2. java代码发送JSON格式的httpPOST请求

    package com.test; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOE ...

  3. Intellij IDEA创建Maven Web项目

    1前言 在创建项目中,IDEA提供了非常多项目模板,比方Spring MVC模板,能够直接创建一个基于Maven的Spring MVC的demo,各种配置都已经设定好了,直接编译部署就能够使用. 最開 ...

  4. mac下配置cocos2d-x3.0

    今天看到3.0的正式版公布了,就马上荡下来试试3.0,以下记录下环境变量配置过程 打开用户文件夹下.bash_profile文件,配置环境 1.首先配置下android sdk,我的是在opt文件夹下 ...

  5. block 解析 - 成员变量

    回顾 在 上一篇 中我们讲了截获变量特性,对于局部变量,变量不加__block修饰符,在block内部是无法修改变量的值.而且 对值类型的修改,如果block初始化后,无法同步到block内部 对于指 ...

  6. Threads and Anonymous Classes in JAVA

    As we all know,a thread is a separate process on your computer.you can run multiple threads all at t ...

  7. document.execCommand()函数可用参数解析

    隐藏在暗处的方法-execCommand() 关键字: javascript document document.execCommand()方法可用来执行很多我们无法实现的操作. execComman ...

  8. Jquery Select 下拉框处理

    $("#select").empty();//清空 $("#select").append($("<option/>").val ...

  9. Arduino 跷跷板(2016-01-04)

    前言这是参加社区活动,用赠送的 LilyPad 来做小实验,也体验了一把艺术的LilyPad!本来是申请 nano 的,不知道怎么的就出错啦,申请成 LilyPad 了,这个实验应该用 nano 比较 ...

  10. android Graphics(一):概述及基本几何图形绘制

    前言:我最近想抽空研究研究android的各种特效,android的特效真是其它平台无法比拟的,而且一个漂亮的UI交互,会给APP增色不少,而学习特效之前,有关graphics绘图的基础知识是必不可少 ...