// Swiss Draw - mjd@cs.auckland.ac.nz #include #include #include #include #include #include #include #include using namespace std; class Player { public: int rank; int spread; int wins; // number times 2 string name; vector scores; Player() : spread(0), wins(0) {} void read(int rankP, int r) { rank = rankP; int score; cin >> name; name.resize(20,' '); for (int i=0; i> score; scores.push_back(score); } } }; ostream& operator<<(ostream &o, const Player &P) { o << setfill(' ') << P.name << setw(3) << P.wins/2; o << (P.wins % 2 ? '+' : ' '); return o << setw(6) << P.spread << endl; } bool less_than(const Player &P1, const Player &P2) // rank less { if (P1.wins < P2.wins) return false; if (P1.wins > P2.wins) return true; if (P1.spread < P2.spread) return false; if (P1.spread > P2.spread) return true; if (P1.rank > P2.rank) return true; else return false; } void play(Player &P1, Player &P2, int num) { int s1 = P1.scores[num]; int s2 = P2.scores[num]; if (s1 == s2) { P1.wins++; P2.wins++; } else if (s1 < s2) { P2.wins += 2; } else { P1.wins += 2; } P1.spread += (s1 - s2); P2.spread += (s2 - s1); return; } class Match { public: string sp1, sp2; Match() {} Match(string s1, string s2) { if (s1 < s2) { sp1 = s1; sp2 = s2; } else { sp2 = s1; sp1 = s2; } } bool operator==(const Match& M2) const { if (sp1==M2.sp1 && sp2==M2.sp2) return true; return false; } bool operator<(const Match& M2) const { if (sp1 < M2.sp1) return true; if (sp1 > M2.sp1) return false; return (sp2 < M2.sp2); } }; bool getPlaylist(const Player *P, const set &played, vector &pList, int &cnt, int idx) { int p = pList.size(); if (cnt == p/2) return true; while (pList[idx] != -1) idx++; // skip to next unassigned for (int p1=idx+1; p10) continue; // played previous round if ( count(pList.begin(), pList.end(), p1) ) continue; pList[idx] = p1; pList[p1] = idx; cnt++; if (getPlaylist(P, played, pList, cnt, idx+1)) return true; else { cnt--; pList[idx] = pList[p1] = -1; } } return false; } int main(int arg, char** argv) { int p, r; while (true) { cin >> p >> r; if (p==0) break; Player *P = new Player[p]; int i; for(i = 0; i < p; i++) // input data { P[i].read(i,r); } set< Match > played; for (i=0; i pList(p); fill(pList.begin(),pList.end(),-1); // non-assignments int cnt=0; assert( getPlaylist(P,played,pList,cnt,0) ); for (int p1=0; p10) continue; play(P[p1], P[pList[p1]], i); played.insert(M); } // sort(P, P+p, less_than); // rerank them for (int k=0; k