U E D R , A S I H C RSS

Ant OnAChessboard/하기웅

소감

-현재 Accepted 되었지만, 시간도 많이 느리고 코드도 길어진거 같아서 나중에 다시 한번 코딩해볼 생각~~

코드

~cpp
#include <iostream> 
#include <cmath> 
using namespace std; 

int step, i, j, temp, counting; 

#define x_loc 1 
#define y_loc 0 

int calculate(int st, int xy) 
{ 
    i=xy; 
    while(true) 
    { 
        counting=1; 
        if(st==1) 
            return 1; 
        if(st>pow(i,2) && st<=pow(i+2,2)) 
        { 
            temp = st-pow(i,2); 
            for(j=1; j<i+1; j++) 
            { 
                temp--; 
                if(temp==0) 
                    return counting; 
                counting++; 
            } 
            for(j=1; j<i+2; j++) 
            { 
                temp--; 
                if(temp==0) 
                    return counting;  
            } 
			counting++;
            for(j=1; j<i+3; j++) 
            { 
                temp--; 
                if(temp==0) 
                    return counting; 
            } 
            counting--; 
            for(j=1; j<i+2; j++) 
            { 
                temp--; 
                if(temp==0) 
                    return counting; 
                counting--; 
            } 
        } 
        i=i+2; 
    } 
} 

int main() 
{ 
    while(cin>>step) 
    { 
        if(step==0) 
            break; 
        cout << calculate(step, x_loc) << " " << calculate(step, y_loc) << endl; 
    } 
    return 0; 
} 

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:30
Processing time 0.0074 sec