uva 10161 - Ant on a Chessboard

来源:互联网 发布:毕业生贷款分期软件 编辑:程序博客网 时间:2024/05/16 16:15

#include<cstdio>#include<cmath>#include<algorithm>#define LL long longint main(){    LL N;    while((scanf("%lld",&N),N)!=0)    {        LL t = sqrt(N);//计算ant在第几层//每层都已平方数开头或结束        if(t*t < N ) t++;        LL  m = ((t-1)*(t-1)+1+t*t)/2;//计算这层中间的数是多少        if(N == m)printf("%lld %lld\n",t,t);        else if(t % 2== 1)//奇数层        {            if(N > m)printf("%lld %lld\n",t-(N-m),t);            else                printf("%lld %lld\n",t,t-(m-N));        }        else            if(t % 2 == 0)//偶数层         {            if(N > m)printf("%lld %lld\n",t,t-(N-m));            else printf("%lld %lld\n",t-(m-N),t);        }    }    return 0;}


原创粉丝点击