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 ...
随机推荐
- poj 3630 Phone List(字典树)
题目链接: http://poj.org/problem?id=3630 思路分析: 求在字符串中是否存在某个字符串为另一字符串的前缀: 即对于某个字符串而言,其是否为某个字符串的前缀,或存在某个其先 ...
- DLL运行时动态加加载的问题
1.error C2440: 'initializing' : cannot convert from 'int (__stdcall *)(void)' to 'void (__cdecl *)(c ...
- 远程读取URL 建议用curl代替file_get_contents
初学php的朋友们,很容易翻一个错误,在写采集程序或者调用api接口总会有线考虑到使用file_get_contents函数来或许内容,程序的访问量不大倒是没什么影响,但是访问量提升了那非常的悲剧了, ...
- C# DES对称加密解密
/// <summary> /// 加密 /// </summary> /// <param name="str"></param> ...
- Regex阅读笔记(五)java操作篇
首先一个demo程序 Java的正则表达式包为java.util.regex,主要是使用其中的Pattern和Matcher. groupCount方法时候都可调用,而大多数方法都必须在匹配尝试成功之 ...
- VCC、VDD、VEE、VSS的区别
电路设计以及PCB制作中,经常碰见电源符号:VCC. VDD.VEE.VSS,他们具有什么样的关系那? 一.解释 VCC:C=circuit 表示电路的意思, 即接入电路的电压 VDD:D=devic ...
- 告别IE给我们的web开发带来的困扰(使用chrome frame v8引擎)
茶爸爸个人微信:benyzhous,公众号:cha-baba欢迎骚扰 由于客户所有机器必须使用IE6浏览器,导致我们在开发项目过程中遇到非常多的样式与性能问题,在偶然的一次使用360软件管家搜索chr ...
- 谈谈Facebook的聊天系统架构
今天看到一份 Facebook 公司 2009 年的 Slideshow, 介绍它的聊天系统架构, 其中的一张图结构非常清晰, 所以我对这张图谈谈我的看法. Web Tier: 用 PHP 开发, 聊 ...
- cocos2dx进阶学习之坐标转换
在cocos2dx中,有四种坐标系 GL坐标系:左下为原点,x轴向右,y轴向上 UI坐标系:左上为原点,x轴向右,y轴向下 世界坐标系:与GL坐标系相同 本地坐标系:是节点(CCNode)的坐标系,原 ...
- 用newLISP读取Hive的元数据
思想是通过调用hive -e命令,然后解析返回的结果. 以下的hive.lsp文件是一个样例,提供了读取本地hive数据库名称.表名,表结构和依据hive表的创建语句生成相应的MySQL的创建语句. ...