UVa:10161 - Ant on a Chessboard

来源:互联网 发布:sql语句查询怎么用 编辑:程序博客网 时间:2024/05/23 11:33

找规律……

#include<stdio.h>#include<math.h>int main(){    int time;    while(scanf("%d",&time)!=EOF){        if(!time)            break;        int s=ceil(sqrt(time));        int N=s*s;        if(s%2){            if(N==time)                printf("%d %d\n",1,s);            else if(N-s+1==time)                printf("%d %d\n",s,s);            else if(time>N-s+1)                printf("%d %d\n",N-time+1,s);            else if(time<N-s+1)                printf("%d %d\n",s,2*s+time-N-1);        }        else{            if(N==time)                printf("%d %d\n",s,1);            else if(N-s+1==time)                printf("%d %d\n",s,s);            else if(time>N-s+1)                printf("%d %d\n",s,N-time+1);            else if(time<N-s+1)                printf("%d %d\n",2*s+time-N-1,s);        }    }    return 0;}


--------------------------------------------------------------------------------------------

          Keep It Simple,Stupid!

--------------------------------------------------------------------------------------------

0 0
原创粉丝点击