UVA - 10161 Ant on a Chessboard
2016-07-14 15:39
204 查看
题目大意:给一个棋盘,输入n,找出n在第几行第几列。
解题思路:找规律。先求最近的完全平方数,得到相应坐标,求 n 与该平方数的差得到 n 的坐标。
解题思路:找规律。先求最近的完全平方数,得到相应坐标,求 n 与该平方数的差得到 n 的坐标。
#include<iostream> #include<cstdio> #include<string.h> #include<stdlib.h> #include<cmath> using namespace std; int main() { long long N; while(scanf("%lld", &N) != EOF && N) { int x = 0, y = 0; long long n = floor(sqrt(N) + 0.5); if (n % 2 == 0) { x = n; y = 1; if (N < n * n) y = y + n * n - N; else if (N > n * n) { x++; y = N - n * n; } } else { y = n; x = 1; if (N < n * n) x = x + n * n - N; else if (N > n * n) { y++; x = N - n * n; } } printf("%d %d\n", x, y); } return 0; }
相关文章推荐
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- 9.401 - Palindromes
- A.537 - Artificial Intelligence?