You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.6 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 10;
struct Node {
int c, d, sum;
bool operator<(const Node &t) const {
//对所有的可能表示法按 a,b,c,d 为联合主键升序排列,最后输出第一个表示法。
//因为这个第一个表示法使得我们首先需要对sum进行升序排列如果sum值一样就需要对c进行升序排列.至于说d,其实无所谓了,因为本题中不可能存在
// sum一样c也一样的场景但也许有的题不行需要写全排序办法
if (sum != t.sum) return sum < t.sum;
if (c != t.c) return c < t.c;
return d < t.d;
}
} f[N];
int n;
int idx;
int main() {
cin >> n;
//枚举c^2+d^2
for (int c = 0; c * c <= n; c++)
for (int d = c; c * c + d * d <= n; d++)
f[idx++] = {c, d, c * c + d * d};
//结构体排序
sort(f, f + idx);
//枚举a^2+b^2
for (int a = 0; a * a <= n; a++) {
for (int b = a; a * a + b * b <= n; b++) {
int t = n - a * a - b * b;
int p = lower_bound(f, f + idx, Node{0, 0, t}) - f;
/*
+lower_bound
0
(1) 使
(2)
(1)
(2)lower_boundNode{0,0,t}
1. sum=tp
2. sum>t
3. t
*/
if (p < idx && f[p].sum == t) {
cout << a << ' ' << b << ' ' << f[p].c << ' ' << f[p].d << ' ' << endl;
return 0;
}
}
}
return 0;
}