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 ...
随机推荐
- 首页 导航栏隐藏 下一级页面显示,pop回来遇到的问题
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationContr ...
- 入门Html
html 超文本标记语言(Hypertext Markup Language),用于描写网页文档的标记语言,最新的版本为5.0.由万维网制定 和更新,其实它本质还是文本文件,只不过需要浏览器来解释显示 ...
- 飘逸的python - 一个最简单的服务器
python拥有这种单独起一个服务器监听端口的能力,用标准库的wsgiref就行. from wsgiref.simple_server import make_server def simple_a ...
- String、StringBuffer、StringBuilder之间区别
String,StringBuffer,StringBuilder 之间区别 在字符串处理中C#提供了String.StringBuffer.StringBuilder三个类.那么他们到底有什么优缺点 ...
- 离线安装.NET 3.5小记
最近为系统新增一个功能,写完以后进行部署,发现在IIS7上部署没有问题,但是IIS6上部署会出现未知情况,具体表现为取不到数据,估计是IIS6和IIS7直接的差异导致程序异常退出. 为了重现异常,在本 ...
- CSS的float与clear
首先要知道,div是块级元素,在页面中独占一行,自上而下排列,也就是传说中的流.如下图: 可以看出,即使div1的宽度很小,页面中一行可以容下div1和div2,div2也不会排在div1后边,因为d ...
- [译]SSIS 通过环境变量配置数据源连接参数
场景 希望在包执行的时候可以随意选择参数,这时候我们可以用环境变量 . 另外所有包都可以用环境变量,有大量包的时候就比较方便. Step 1: 创建SSIS包 在Data Flow Task里面创建 ...
- 从开发到部署,使用django创建一个简单可用的个人博客
本文参考于: 简书-Django搭建简易博客教程:http://www.jianshu.com/p/d15188a74104 自强学堂-Django基础教程:http://www.ziqiangxue ...
- MAVEN入门(二)
一.IDEA+MAVEN+Tomcat7 创建一个简单的Web app 1.用IDEA创建一个maven项目 注意: 红色部分一定要自己手选本地配置好的maven_home的地址,否则IDEA会选用内 ...
- 64位win8 配置Apache2.4+mod_msgi4.4.21+django1.8.6+python3.4
学习了很多前人分享的资料,整理如下: 安装步骤: 一.安装python3.4 下载 python-3.4.3.amd64.msi 直接安装 地址:https://www. ...