Bootstrap

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 ************************/
;