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 ...
随机推荐
- HTTP基本协议(查看网页代码)
此示例已实现查看网页的代码来理解HTTP基本协议: (返回的是百度首页的网页代码) import java.io.BufferedReader; import java.io.IOException; ...
- delphi webbrowser 经常用法演示样例
var Form : IHTMLFormElement ; D:IHTMLDocument2 ; begin with WebBrowser1 do begin D := Document as IH ...
- Ext.net-00 VS配置
1.configSections 节点配置 <section name="extnet" type="Ext.Net.GlobalConfig" requ ...
- HTML之标签
一.HTML 标签 HTML 标记标签通常被称为 HTML 标签 (HTML tag). •HTML 标签是由尖括号包围的关键词,比如 <html> •HTML 标签通常是成对出现的,比如 ...
- ansible变量
ansible变量 (部分内容摘自互联网,非官方,描述不一定正确) 变量种类: 内置变量facts: 自定义变量: 命令行传递的变量 roles传递的变量 主机变量 组变量 内置变量facts: 由远 ...
- 总线接口与计算机通信(四)USB外部总线(初级认识)
USB简介 USB是英文Universal Serial BUS(通用串行总线)的缩写,是一个外部总线标准,用于规范电脑与外部设备的连接和通讯,是应用在PC领域的接口技术.USB接口支持设备的即插 ...
- BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )
tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...
- BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会( dp + dfs )
选取任意一个点为root , size[ x ] 表示以 x 为根的子树的奶牛数 , dp一次计算出size[ ] && 选 root 为集会地点的不方便程度 . 考虑集会地点由 x ...
- WebSphere优化
优化WebSphere WebSphere里的profile刚配完,一般默认的heapsize即Xms与Xmx值只有256mb,而IBM WAS是几个J2EE服务器中最吃内存的机器,在布署一些EAR应 ...
- win7 VMware Workstation Centos6.5虚机桥接上网设置 详解(靠谱)
1.VMware Workstation 设置 2. vim /etc/sysconfig/network-scripts/ifcfg-eth0 NAME="System eth0" ...