SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2
题目来源: 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的更多相关文章
- 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 582 Div II Level One: SemiPerfectSquare
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12580 比较简单,代码如下: #include <ios ...
- SRM 582 Div II Level Two SpaceWarDiv2
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 #include <iostream> # ...
- SRM 582 Div II Level Three: ColorTheCells, Brute Force 算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12581 Burte Force 算法,求解了所有了情况,注意 ...
- SRM 583 Div II Level One:SwappingDigits
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609 #include <iostream> # ...
- SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...
- 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 ...
随机推荐
- centos 安装 erlang
1.首先下载erlang 安装源文件 可以在官网上下载 : http://www.erlang.org/ 官网上提供多个版本: 2.下载完成后将R16B01 Source File对应的 ot ...
- C# MyNewQueue 消息队列
C# using System; using System.Messaging; using System.Drawing; using System.IO; namespace MyProject ...
- 在CheckBox中,仅仅允许选择一项
作用相当于RadioButonList <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=" ...
- linq to sql用partial扩展属性,创建一个部分类(用于多表连接)
1.在窗体中创建dataGridView显示表: using System; using System.Collections.Generic; using System.ComponentModel ...
- [Linux命令]查看Linux系统相关命令
#查看系统内核/操作系统/CPU信息 uname -a #返回:内核名 主机名 Linux内核版本 内核编译日期 操作系统版本 CPU型号 硬件平台 GNU/Linux#查看系统是32位还是64位un ...
- Recursive Depth first search graph(adj matrix)
1 深度优先遍历邻接矩阵 1 邻接矩阵初始化 2 访问数组初始化 3 深度优先遍历邻接矩阵图 算法如下: bool MGraph[128][128]; bool visit[128]; int vex ...
- asp.net mvc 客户端(&)中检测到有潜在危险的 Request.Path 值。
出现这个错误后,试过 <pages validateRequest="false"> <httpRuntime requestValidationMode=&qu ...
- QtInternal 之 高效使用QString(使用QLatin1String,QStringRef,QStringBuilder,QStringMatcher等相关类)
注意:本文翻译自 http://developer.qt.nokia.com 中的 UsingQStringEffectively ,中文译文见 简体中文版 ,如果你对翻译wiki感兴趣 ...
- app添加辅助功能时,需要注意的测试点
最近项目里需要在辅助功能添加对应的服务,来支持对应的功能实现: 1.对用户添加app进行信息管理功能中,该app有对应的通知或信息时在app的logo上显示提示标志. 2.用户下载一款app后能够自动 ...
- 将HDC保存为BMP文件
HDC在MSDN中的全称为:The handle of device context.通常,我们都是用来做相应的显示操作. 熟悉WIN32的朋友对于其应该不会陌生,经常采用GetDC,G ...