1:#include <string>
2:#include <vector>
3:#include <fstream>
4:#include <sstream>
5:#include <cassert>
6:#include <iostream>
7:#include <algorithm>
8:
9:using namespace std;
10:
11:#define PROB_NAME "A"
12:
13:struct Player
14:{
15: string name;
16: int number, role, exp;
17: bool captain, inarrange;
18:
19: Player (const string & line)
20: : number (0), exp (0), captain (false), inarrange (false)
21: {
22: stringstream ss (line);
23: ss >> number;
24: if (0 == number) return;
25:
26: char foo;
27: ss >> name >> foo;
28: role = (int)string("GDMS").find(foo);
29: assert (role >= 0 && role < 4);
30:
31: int y1, y2;
32: while (ss >> y1 >> foo >> y2)
33: exp += y2 - y1 + 1;
34: }
35: // Compare according to precedence in arrange
36: static bool CompArrange (const Player & p1, const Player & p2)
37: {
38: if (p1.role != p2.role) return p1.role < p2.role;
39: else return p1.number < p2.number;
40: }
41: // Compare according to precedence for captaincy(!)
42: static bool CompCaptaincy (const Player & p1, const Player & p2)
43: {
44: if (p1.inarrange != p2.inarrange) return p1.inarrange;
45: else if (p1.exp != p2.exp) return p1.exp > p2.exp;
46: else return p1.number > p2.number;
47: }
48: // Compare according to precedence for display
49: static bool CompListing (const Player & p1, const Player & p2)
50: {
51: if (p1.inarrange != p2.inarrange) return p1.inarrange;
52: else if (p1.captain != p2.captain) return p1.captain;
53: else if (p1.role != p2.role) return p1.role < p2.role;
54: else return p1.number < p2.number;
55: }
56:};
57:
58:int main ()
59:{
60: ifstream fin (PROB_NAME ".in");
61:
62: while (0 == 0)
63: {
64: vector<Player> p;
65: int avroles [4] = {0, 0, 0, 0};
66:
67: for (unsigned i = 0; i < 22; ++i)
68: {
69: string ln;
70: getline (fin, ln);
71: p.push_back (Player(ln));
72: if (0 == p.back().number) break;
73: avroles[p.back().role]++;
74: }
75: if (0 == p.size() || 0 == p.back().number) break;
76:
77: int a[4] = {1, 0, 0, 0};
78: char foo;
79: fin >> a[1] >> foo >> a[2] >> foo >> a[3];
80:
81: if (a[0] > avroles[0] || a[1] > avroles[1] ||
82: a[2] > avroles[2] || a[3] > avroles[3])
83: cout << "IMPOSSIBLE TO ARRANGE" << endl;
84: else
85: {
86: sort (p.begin(), p.end(), Player::CompArrange);
87: for (unsigned i = 0; i < p.size(); ++i)
88: if (a[p[i].role]-- > 0) p[i].inarrange = true;
89: sort (p.begin(), p.end(), Player::CompCaptaincy);
90: p[0].captain = true;
91: sort (p.begin(), p.end(), Player::CompListing);
92: for (unsigned i = 0; i < 11; ++i)
93: cout << p[i].number << " " << p[i].name
94: << " " << "GDMS"[p[i].role] << endl;
95: cout << endl;
96: }
97: }
98: return 0;
99:}
Monday, December 18, 2006
Sharif ICPC Regionals 2006 - Problem A
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment