Red Huang

Red Huang

TopCoder SRM 345 DIV1 パスファインディング

非常に難しい問題で、4 つの象限をそれぞれ考慮すればよいです

// 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  

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。