SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2

Source: Internet
Author: User

Note that you only need to connect the strings in the ratings parameter directly, without adding spaces behind each element. at the beginning, I thought that when each element is connected, it should be separated by spaces, and then duplicated elements are removed. As a result, system test has an error and debugging has not been completed for half a day. the problem is that there is no duplicate data. it can be seen that some of the topics on TopCoder seem simple, but there is actually a pitfall, and such a pitfall sample cannot be tested. After passing the sample, we will submit, and the system test will go down directly, it is worth noting that the accuracy of this question is only % 10. the Code is as follows:

#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;    }}; 

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.