topcode SRM 577 DIV1 EllysRoomAssignmentsDiv1
2013-04-29 11:07
357 查看
注意分情况求期望
(1)只分配一个房间时,也就是人数少于20,对应测试用例1
(2)刚好完全分配时,对应测试用例3
(3)不能完全分配,最后还剩余的竞技者的数量小于房间数,随机分配
a) 当elly刚好在最后剩余的里面,也就是elly排最后几名,对应测试用例4
b) 当elly不在最后剩余的里面 ,对应测试用例0和2
(1)只分配一个房间时,也就是人数少于20,对应测试用例1
(2)刚好完全分配时,对应测试用例3
(3)不能完全分配,最后还剩余的竞技者的数量小于房间数,随机分配
a) 当elly刚好在最后剩余的里面,也就是elly排最后几名,对应测试用例4
b) 当elly不在最后剩余的里面 ,对应测试用例0和2
#include <iostream> #include <numeric> #include <vector> #include <string> #include <algorithm> #include <sstream> #include <cmath> using namespace std; class EllysRoomAssignmentsDiv1{ public: double getAverage(vector <string> ratings){ string split=""; string all = accumulate(ratings.begin(),ratings.end(),split); stringstream sst(all); vector<int> score; int tmp; while(sst >> tmp) score.push_back(tmp); int score_elly = score[0]; sort(score.begin(),score.end(),greater<int>()); int cnt_elly = 0; for(int i = 0 ; i < score.size(); i ++ ){ if( score[i] == score_elly) { cnt_elly = i;break; } } int R = score.size()%20 ? score.size()/20+1 : score.size()/20; double value = 0; for(int i = 0 ; i < score.size()/R; i ++ ){ if( i == cnt_elly/R ) continue; double sum = 0; for(int j = 0; j < R; j ++ ) sum +=score[R*i+j]; value +=sum/R; } if(R == 1){ return (value+score_elly)/score.size(); } else if(score.size()%R){ double otherValue = 0; int otherStart = score.size()/R*R; if(cnt_elly < otherStart){ for(int i =otherStart; i < score.size(); i ++ ) otherValue += score[i]; otherValue /=(score.size()-otherStart); return (value+otherValue+score_elly)/(score.size()/R+1)/R*(score.size()-otherStart) + (value+score_elly)/(score.size()/R)/R*(R-score.size()+otherStart); } else{ return (value+score_elly)/(score.size()/R+1); } } else{ return (value+score_elly)/(score.size()/R); } } };
相关文章推荐
- topcode SRM 577 DIV2 EllysNewNickname
- topcode SRM 577 DIV2 EllysCoprimesDiv2
- TopCoder SRM144 DIV1(one)
- TopCoder SRM 659 Div2 Problem 500 - PublicTransit (思维)
- topcoder SRM div 2 level 1
- topcoder srm 682 div1 -3
- Top Coder SRM 614 DIV 2
- [容斥] Topcoder SRM div1-3 12004. SetAndSet
- Topcode 599 div2 第一题
- Topcoder SRM 668 DIV 2
- Topcoder SRM 573 WolfPackDivTwo
- TopCoder SRM 649 Div2 Problem 500 - CartInSupermarketEasy (区间DP)
- topcoder SRM588 DIV1 解题报告
- Topcode SRM 556
- TOPCODER/SRM 566 DIVII(250、500、1000题)(1000PT暂未附上代码)
- TopCoder SRM 140 Div2 第3题
- TopCoder SRM 681 Div. 2 Problem 500 - ExplodingRobots (枚举)
- TopCoder SRM 668 Div2 Problem 1000 - AnArray (数学)
- Topcoder SRM 688 div2
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串