UVA - 10161 Ant on a Chessboard

原创 2016年08月30日 23:53:38

题目大意:一只蚂蚁在棋盘上以一定的规则爬行,求出一定时间过后蚂蚁的位置。

解题思路:如图,时间与位置的关系。先算出完整的平方部分到哪里,剩下的时间分为对角线之前和对角线之后分别修改 x , y 值

这里写图片描述

#include<cstdio>
int main() {
  int t ;
  while( scanf("%d",&t) , t ) {
      int x = 1, y = 1 , squ = 1, la;
      if( t == 1 ) { printf("1 1\n"); continue;}
      for(int i = 1; i*i <= t ; i++ ) 
          squ = i;
      t = t - squ*squ;  
      if( squ % 2 ) 
           y = squ;
      else x = squ;
      if( !t ) {  printf("%d %d\n", x , y ); continue; }  
      if( t <= squ + 1 ) {
         if( x == 1) {
            y += 1;
            x = t;
         }        
         else if( y == 1 ) { 
            x += 1;
            y = t;
          }
      }
     else {
        if( y == 1 ) {
            y += squ;
            x -= t - ( squ + 1 ) - 1 ;
         }
        else if( x == 1) {
           x += squ;
           y -= t - ( squ + 1 ) - 1;
        }
     }
    printf("%d %d\n", x , y );
 }
 return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kirsi0/article/details/52374435

Web Services: Building Reusable Web Components with SOAP and ASP.NET(English)

 Web Services: Building Reusable Web Components with SOAP and ASP.NETDavid S. PlattThis article assu...
  • x86
  • x86
  • 2001-02-08 09:41:00
  • 1482

UVa 10161 Ant on a Chessboard (简单数学)

10161 - Ant on a Chessboard Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=co...
  • synapse7
  • synapse7
  • 2013-09-14 12:43:16
  • 915

uva 10161 Ant on a Chessboard(蛇型矩阵)

Problem A.Ant on a Chessboard    Background   One day, an ant called Alice came to an M*M ches...
  • u011328934
  • u011328934
  • 2013-07-20 13:47:37
  • 926

UVA 10161 Ant on a Chessboard

Ant on a Chessboard    Background   One day, an ant called Alice came to an M*M chessbo...
  • u011639256
  • u011639256
  • 2013-11-03 19:34:02
  • 448

UVa 10161: Ant on a Chessboard

很简单的一题找规律题。 我的解题代码如下: #include #include #include #include #include #include #include using...
  • u011399686
  • u011399686
  • 2013-08-03 13:25:25
  • 808

UVA - 10161 - Ant on a Chessboard

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&p...
  • u014304261
  • u014304261
  • 2014-05-11 21:32:26
  • 545

UVa:10161 - Ant on a Chessboard

找规律…… #include #include int main(){ int time; while(scanf("%d",&time)!=EOF){ if(!ti...
  • Freeddong
  • Freeddong
  • 2014-09-18 22:18:31
  • 229

Uva 10161 Ant on a Chessboard

Problem A.Ant on a Chessboard    Background   One day, an ant called Alice came to an ...
  • HelloWorld10086
  • HelloWorld10086
  • 2014-07-22 09:01:17
  • 546

UVA 10161 Ant on a Chessboard

题目棋盘上的蚂蚁分析 按路线把这个表格铺开~ [1] (1, 1) 2 [3] 4 (1, 2) (2, 2) (2, 1) 9 8 [7] 6 5 (...
  • lab103
  • lab103
  • 2015-07-27 18:33:26
  • 133
收藏助手
不良信息举报
您举报文章:UVA - 10161 Ant on a Chessboard
举报原因:
原因补充:

(最多只允许输入30个字)