Skip to content

Instantly share code, notes, and snippets.

@benblack769
Created October 3, 2016 02:46
Show Gist options
  • Save benblack769/059cc7e1c488b30d1238116ea6904e19 to your computer and use it in GitHub Desktop.
Save benblack769/059cc7e1c488b30d1238116ea6904e19 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <sstream>
#include <array>
using namespace std;
vector<string> split(string line){
stringstream ss(line); // Insert the string into a stream
vector<string> tokens; // Create vector to hold our words
string buf;
while (ss >> buf){
tokens.push_back(buf);
}
return tokens;
}
string get_next(){
string str;
getline(cin,str);
return str;
}
struct Pos{
bool win;
int x;
int y;
};
constexpr size_t maxsize = 100+1;
Pos table[maxsize][maxsize][maxsize];
#define access(cs) (table[cs[0]][cs[1]][cs[2]])
Pos comp_pos(array<int,3> coords){
for (int y = 0; y < 3; y++){
for(int x = coords[y]-1; x >= 0; x--){
array<int,3> delc = coords;
for(int i = y; i < 3; i++){
delc[i] = min(x,delc[i]);
}
Pos p = access(delc);
if(!p.win){
return Pos{true,x,y};
}
}
}
return Pos{false,-1,-1};
}
void compute_table(){
array<int,3> coords;
table[0][0][0] = Pos{true,-1,-1};
for(coords[0] = 1; coords[0] <= maxsize-1; coords[0]++){
for(coords[1] = 0; coords[1] <= coords[0]; coords[1]++){
for(coords[2] = 0; coords[2] <= coords[1]; coords[2]++){
access(coords) = comp_pos(coords);
}
}
}
}
int main(){
compute_table();
int test_cases = stoi(get_next());
for(int casen = 0; casen < test_cases; casen++){
vector<string> pstr = split(get_next());
array<int,3> coords = {stoi(pstr[1]),stoi(pstr[2]),stoi(pstr[3])};
Pos p = access(coords);
cout << casen+1;
if(p.win){
cout << " W " << p.x+1 << " " << p.y+1;
}
else{
cout << " L";
}
cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment