\(\color{black}\texttt{A. 数字涡旋}\)
题目描述
有一张无线大的表格,里面填着所有正整数,表格如下:
\[\begin{matrix} 1&2&9&\dots\\ 4&3&8\\ 5&6&7\\ \vdots&&&\ddots \end{matrix} \]求数字 \(N\) 出现在表格的几行几列。
思路
推式子体。
代码
#include<bits/stdc++.h>
using namespace std;
int t, n, k;
int Sqrt(int x) {
int l = 1, r = 31624;
for(; l < r; ) {
int mid = (l + r) >> 1;
(1ll * mid * mid >= x ? r = mid : l = mid + 1);
}
return l;
}
void Solve() {
cin >> n;
k = Sqrt(n);
int d = k * k - n;
if(k % 2 == 0) {
if(d < k) {
cout << k << " " << 1 + d << "\n";
}else {
cout << k - (d - k + 1) << " " << k << "\n";
}
}else {
if(d < k) {
cout << 1 + d << " " << k << "\n";
}else {
cout << k << " " << k - (d - k + 1) << "\n";
}
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
for(cin >> t; t--; Solve()) {
}
return 0;
}
标签:信息学,return,matrix,表格,int,mid,Sqrt,2024,逐月
From: https://www.cnblogs.com/yaosicheng124/p/18286088