1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
| // // main.cpp // PGA // // Created by zhangmin chen on 2019/4/26. // Copyright © 2019 zhangmin chen. All rights reserved. //
using namespace std; typedef long long llong;
// const int maxn = 145; const int przn = 70;
class Player { public: string name; double prize; bool amat; bool t; int rnd[4]; int dq; int rank; int pre, tot; // pre used to decide which one can be in round[3, 4], make the cut // tot used to divide money // only made the cut plyer can get money // divide prize: // 1 parallel // 2 amt don't get prize // 3 get prize? Not amter && rank[1,70] // DQ: // 1 DQ > 2, plyer can make the cut // 2 but not rank in rnd[3,4] // make the cut: // DQ == 0 || DQ > 2 ---> make the cut // rank: // only DQ == 0 rank Player() { name.clear(); prize = 0.0; amat = t = false; memset(rnd, 0, sizeof(rnd)); dq = 4; rank = 0; pre = tot = 0; } void init() { prize = 0.0; amat = t = false; memset(rnd, 0, sizeof(rnd)); dq = 4; rank = 0; pre = tot = 0; } };
int n;
vector<Player> plyers; double priz[przn]; double sum;
int str2num(const string& str) { int val = 0; for(int i = 0; i < str.length(); i++) { val = val * 10 + str[i] - '0'; } //debug(val); return val; }
void init() { // //for(int i = 0; i < n; i++) plyers[i].init(); plyers.clear(); memset(priz, 0, sizeof(priz)); scanf("%lf", &sum); for(int i = 0; i < 70; i++) { scanf("%lf", &priz[i]); priz[i] = priz[i] / 100.0 * sum; } }
void initPlyer() { //scanf("%d", &n); cin >> n; plyers.resize(n+1); string str; getline(cin, str); for(int i = 0; i < n; i++) { plyers[i].tot = 0; getline(cin, str); plyers[i].name = str.substr(0, 20); str = str.substr(20); if(plyers[i].name.find('*') != string::npos) { plyers[i].amat = true; } stringstream ss(str); //string data; // is >> data for(int j = 0; j < 4; j++) { string data; ss >> data; if(data == "DQ") { plyers[i].dq = j; break; } else { plyers[i].rnd[j] = str2num(data); } if(j < 2) { plyers[i].pre += str2num(data); } plyers[i].tot += str2num(data); } // debug("----"); } }
bool cmp1(const Player& lhs, const Player& rhs) { if(lhs.dq > 1 && rhs.dq > 1) return lhs.pre < rhs.pre; return lhs.dq > rhs.dq; }
int makeCut() { sort(plyers.begin(), plyers.begin() + n, cmp1); int pos = 0; while (pos < min(70, n) && plyers[pos].dq > 1) { pos++; } // [0, 69] --> 70 while (plyers[pos].dq > 1 && plyers[pos].pre == plyers[pos-1].pre) { pos++; } return pos; }
// usage: int pos = makeCut // getRank(pos)
bool cmp2(const Player& lhs, const Player& rhs) { if(lhs.dq != rhs.dq) return lhs.dq > rhs.dq; if(lhs.tot != rhs.tot) return lhs.tot < rhs.tot; return lhs.name < rhs.name; }
// important! // difficult: parallel situation void getRank(int num) { // sort(plyers.begin(), plyers.begin() + num, cmp2); // divide money // 1. parallel // 2. amte cannot get money // no amte and rank from [0, 70] // now: plyers[0...num-1] int k = 0, rkp = 0; int rk = 0; while(k < num) { if(plyers[k].dq < 4) break; // parallel: [k, p) rank: rk int p = k, cnt = 0; double sum = 0.0; int prll = 0; while(plyers[p].dq == 4 && plyers[p].tot == plyers[k].tot) { // if(!plyers[p].amat) { // sum += priz[rkp + cnt]; cnt++; // } p++; prll++; } sum /= cnt; // assign prize: for(int i = k; i < p; i++) { plyers[i].rank = rk + 1; // prize is not enough if(rkp > 69) { plyers[i].amat = true; plyers[i].t = false; } if(!plyers[i].amat) { plyers[i].prize = sum; plyers[i].t = cnt > 1; } } // [k, p) rank: rk // rk [0, 70) // [p, ...) rank: rk += cnt // plyers[].rank = rk + 1; k = p; rkp += cnt; rk += prll; } }
void printAns(int num) { // printf("Player Name Place RD1 RD2 RD3 RD4 TOTAL Money Won\n"); printf("-----------------------------------------------------------------------\n"); for(int i = 0; i < num; i++) { printf("%-21s", plyers[i].name.c_str()); if(plyers[i].dq < 4) printf(" "); else { char t[5]; sprintf(t, "%d%c", plyers[i].rank, plyers[i].t ? 'T' : ' '); printf("%-10s", t); } for(int j = 0; j < plyers[i].dq; j++) printf("%-5d", plyers[i].rnd[j]); for(int j = plyers[i].dq; j < 4; j++) printf(" "); if(plyers[i].dq < 4) printf("DQ"); else if(!plyers[i].amat) printf("%-10d", plyers[i].tot); else printf("%d", plyers[i].tot); if(plyers[i].dq < 4 || plyers[i].amat) { printf("\n"); continue; } printf("$%9.2lf\n", plyers[i].prize); //int ans = floor((plyers[i].prize + 0.0050001) * 100); //plyers[i].prize = ans / 100.0; //cout.setf(ios::right); //cout << "$" << setw(9) << fixed << setprecision(2) << plyers[i].prize << endl; //int ans = (int)((plyers[i].prize + 0.0005) * 10000); //printf("$%9.2lf\n", ans / 1000.0); } }
// attend rnd[3,4], we need plyer.dq > 2
int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int kase; scanf("%d", &kase); while(kase--) { init(); // get prize data initPlyer(); int num = makeCut(); getRank(num); printAns(num); if(kase) printf("\n"); } }
|