滿強烈的思考題,四個象限分別考慮即可
// BEGIN CUT HERE
// END CUT HERE
#line 5 "GCAcode.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
#ifdef DEBUG
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...) printf("DEBUG: "),printf(__VA_ARGS__)
#else
#define VAR(a,b) __typeof(b) a=(b)
#define debug(...)
#endif
typedef unsigned int uint;
typedef long long int Int;
typedef unsigned long long int UInt;
#define Set(a,s) memset(a,s,sizeof(a))
#define Pln() printf("\n")
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define M MAX_LIMITS
#define PB push_back
#define oo INT_MAX
#define FOR(a,b) for(VAR(a,(b).begin());a!=(b).end();++a)
#define eps 1e-9
#define X first
#define Y second
inline bool xdy(double x,double y){return x>y+eps;}
inline bool xddy(double x,double y){return x>y-eps;}
inline bool xcy(double x,double y){return x<y-eps;}
inline bool xcdy(double x,double y){return x<y+eps;}
const Int mod=1000000007;
class Pathfinding
{
public:
bool odd(int x){return x%2==1;}
bool even(int x){return (x%2==0);}
int getDirections(int x, int y){
int ans=abs(x)+abs(y);
if(x>=0&&y>=0){
x=abs(x);y=abs(y);
if(odd(x)&&odd(y))return ans+2;
else return ans;
}
if(x>0&&y<0){
x=abs(x);y=abs(y);
if(even(x)&&odd(y))return ans+2;
else return ans;
}
if(x<0&&y>0){
x=abs(x);y=abs(y);
if(odd(x)&&even(y))return ans+2;
else return ans;
}
if(x<=0&&y<=0){
x=abs(x);y=abs(y);
if(even(x)&&even(y))return ans+4;
else return ans+2;
}
return ans;
}
// 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();
if ((Case == -1) || (Case == 6)) test_case_6();
}
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 int &Expected, const int &Received) { cout << "Test Case #" << Case << "..."; if (Expected == Received) cout << "PASSED" << endl; else { cout << "FAILED" << endl; cout << "\tExpected: \"" << Expected << '\"' << endl; cout << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() {
int Arg0 = 0;
int Arg1 = -4;
int Arg2 = 8;
verify_case(0, Arg2, getDirections(Arg0, Arg1)); }
void test_case_1() {
int Arg0 = 5;
int Arg1 = -4;
int Arg2 = 9;
verify_case(1, Arg2, getDirections(Arg0, Arg1)); }
void test_case_2() {
int Arg0 = 5;
int Arg1 = 4;
int Arg2 = 9;
verify_case(2, Arg2, getDirections(Arg0, Arg1)); }
void test_case_3() {
int Arg0 = -1;
int Arg1 = -4;
int Arg2 = 7;
verify_case(3, Arg2, getDirections(Arg0, Arg1)); }
void test_case_4() {
int Arg0 = 0;
int Arg1 = 0;
int Arg2 = 0;
verify_case(4, Arg2, getDirections(Arg0, Arg1)); }
void test_case_5() {
int Arg0 = 0;
int Arg1 = -4;
int Arg2 = 8;
verify_case(5, Arg2, getDirections(Arg0, Arg1)); }
void test_case_6() {
int Arg0 = -5;
int Arg1 = 4;
int Arg2 = 11;
verify_case(6, Arg2, getDirections(Arg0, Arg1)); }
// END CUT HERE
};
// BEGIN CUT HERE
int main()
{
Pathfinding ___test;
___test.run_test(-1);
return 0;
}
// END CUT HERE
留言
張貼留言