XJOI 3410 看图找规律 题解
英文
Time Limit:0.5s Memory Limit:32M
Description
The position of 8 is (2,3),please tell us the position of n.
1<=n<=10^15
Input
An integer x
Output
Two integer
Sample Input1
8
Sample Output1
2 3
Sample Input2
20
Sample Output2
5 4
中文
时间:0.2 空间:32M
题目描述:
数字8的坐标是(2, 3)
请问n的坐标是什么
输入格式:
输入一个整数x
输出格式:
输出两个整数
样例输入1:
8
样例输出1:
2 3
样例输入2:
20
样例输出2:
5 4
约定:
1<=n<=10^15
提示:
以平方数为核心,仔细寻找规律即可!注意n,只能找数学规律
代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std ;
int main ( )
{
long long x ;
scanf ( "%lld" , & x ) ;
long long t1 = int ( ceil ( sqrt ( x ) ) ) ;
long long t2 = t1 * t1 ;
if ( t1 % 2 == 0 )
{
long long k = t2 - x ;
if ( k < t1 ) printf ( "%lld %lld" , t1 , k + 1 ) ;
else
{
k = k - t1 + 1 ;
k = t1 - k ;
printf ( "%lld %lld" , k , t1 ) ;
}
} else
{
long long k = t2 - x ;
if ( k < t1 ) printf ( "%lld %lld" , k + 1 , t1 ) ;
else
{
k = k - t1 + 1 ;
k = t1 - k ;
printf ( "%lld %lld" , t1 , k ) ;
}
}
return 0 ;
}
相关链接:
XJOI 题解小全:
https://blog.csdn.net/zj_mrz/article/details/80949787
XJOI 3265 Climb the stairs 爬楼梯 题解:
https://blog.csdn.net/zj_mrz/article/details/80970052
XJOI 3266 Dyeing 染色 题解:
https://blog.csdn.net/zj_mrz/article/details/81060961
XJOI 1327 The union set 区间合并 题解:
https://blog.csdn.net/zj_mrz/article/details/81043138
XJOI 3287 离散化 题解:
https://blog.csdn.net/zj_mrz/article/details/81037239