#include #include #include using namespace std; int r, c, k; bool flag = false; vector < pair > nim; void readDir(){ string dir; int size; cin >> dir >> size; /* if(dir == "left"){ nim[0] -= size; } else if(dir == "right"){ nim[1] -= size; } else if(dir == "top"){ nim[2] -= size; } else if(dir == "bottom"){ nim[3] -= size; } */ for(int i = 0; i < 4; ++i){ if(nim[i].second == dir){ nim[i].first -= size; break; } } } void strategia1(){ cout << nim[3].second << " " << nim[3].first << endl; nim[3].first = 0; } void strategia2(){ if(nim[3].first == nim[2].first){ if (!flag) cout << "pass" << endl; else { cout << nim[3].second << " " << nim[3].first << endl; nim[3].first = 0; } } else { cout << nim[3].second << " " << nim[3].first - nim[2].first << endl; nim[3].first = nim[2].first; } } void strategia3(){ if(nim[3].first == nim[2].first){ cout << "pass" << endl; } else { cout << nim[3].second << " " << nim[3].first - nim[2].first << endl; nim[3].first = nim[2].first; } } void strategia4(){ if(nim[3].first == nim[2].first){ cout << "pass" << endl; } else { cout << nim[3].second << " " << nim[3].first - nim[2].first << endl; nim[3].first = nim[2].first; } } bool strategia() { sort(nim.begin(), nim.end()); if (nim[3].first == 0) return false; //int z = zeros(); //if (z == 4 ) return true; if (nim[2].first == 3 ) strategia1(); if (nim[1].first == 2 ) strategia2(); if (nim[0].first == 1 ) strategia2(); else strategia2(); sort(nim.begin(), nim.end()); if (nim[3].first == 0) return false; flag = true; return true; } int main(){ //nim.resize(4) cin >> r >> c >> k; //nim[0] = c, nim[1] = c, nim[2] = r, nim[3] = r; nim.push_back(make_pair(c, "left")); nim.push_back(make_pair(c, "right")); nim.push_back(make_pair(r, "top")); nim.push_back(make_pair(r, "bottom")); int x, y; string dir; int size; //cout << nim[0].first << " " << nim[1].first << " " << nim[2].first << " " << nim[3].first << " " << endl; for(int i = 0; i < k; ++i){ cin >> x >> y; nim[0].first = min(nim[0].first, y-1); nim[1].first = min(nim[1].first, c-y); nim[2].first = min(nim[2].first, x-1); nim[3].first = min(nim[3].first, r-x); //cout << nim[0].first << " " << nim[1].first << " " << nim[2].first << " " << nim[3].first << " " << endl; } sort(nim.begin(), nim.end()); //cout << nim[0].first << " " << nim[1].first << " " << nim[2].first << " " << nim[3].first << " " << endl; while (strategia()) { //cout << nim[0].first << " " << nim[1].first << " " << nim[2].first << " " << nim[3].first << " " << endl; readDir(); } return 0; }