Created
May 29, 2015 10:07
-
-
Save iseki-masaya/e6ae3dee9d8f5e74aaed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <string> | |
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
#include <list> | |
#include <algorithm> | |
#include <sstream> | |
#include <set> | |
#include <cmath> | |
#include <map> | |
#include <unordered_map> | |
#include <unordered_set> | |
#include <stack> | |
#include <queue> | |
#include <cstdio> | |
//#include <cstdlib> | |
#include <cstring> | |
#include <numeric> | |
#include <bitset> | |
#include <deque> | |
#include <memory> | |
const long long LINF = (5e17); | |
const int INF = 1000000000; | |
#define EPS 1e-7 | |
const int MOD = 1000000007; | |
using namespace std; | |
class FoxAndChess { | |
public: | |
typedef pair<char, int> P; | |
bool isPossble(P begin, P target) { | |
if (begin.first != target.first) | |
return false; | |
if (begin.first == 'R') | |
return begin.second <= target.second; | |
else | |
return begin.second >= target.second; | |
} | |
string ableToMove(string begin, string target) { | |
queue<P> que; | |
for (int i=0; i<target.size(); ++i) | |
if (target[i] != '.') | |
que.push(P(target[i], i)); | |
for (int i=0; i<begin.size(); ++i) { | |
if (begin[i] == '.') | |
continue; | |
if (que.empty() || !isPossble(P(begin[i], i), que.front())) | |
return "Impossible"; | |
que.pop(); | |
} | |
return que.empty() ? "Possible" : "Impossible"; | |
} | |
// BEGIN CUT HERE | |
public: | |
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); } | |
private: | |
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } | |
void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } | |
void test_case_0() { string Arg0 = "R..."; string Arg1 = "..R."; string Arg2 = "Possible"; verify_case(0, Arg2, ableToMove(Arg0, Arg1)); } | |
void test_case_1() { string Arg0 = "..R."; string Arg1 = "R..."; string Arg2 = "Impossible"; verify_case(1, Arg2, ableToMove(Arg0, Arg1)); } | |
void test_case_2() { string Arg0 = ".L.R.R."; string Arg1 = "L...R.R"; string Arg2 = "Possible"; verify_case(2, Arg2, ableToMove(Arg0, Arg1)); } | |
void test_case_3() { string Arg0 = ".L.R."; string Arg1 = ".R.L."; string Arg2 = "Impossible"; verify_case(3, Arg2, ableToMove(Arg0, Arg1)); } | |
void test_case_4() { string Arg0 = "LRLLRLRLLRLLRLRLRL"; string Arg1 = "LRLLRLRLLRLLRLRLRL"; string Arg2 = "Possible"; verify_case(4, Arg2, ableToMove(Arg0, Arg1)); } | |
void test_case_5() { string Arg0 = "L"; string Arg1 = "."; string Arg2 = "Impossible"; verify_case(5, Arg2, ableToMove(Arg0, Arg1)); } | |
// END CUT HERE | |
}; | |
// BEGIN CUT HERE | |
int main() { | |
FoxAndChess ___test; | |
___test.run_test(-1); | |
} | |
// END CUT HERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment