'commit'
This commit is contained in:
38
TangDou/CSP-J/J2-2021/AcWing1221_ManualHash.cpp
Normal file
38
TangDou/CSP-J/J2-2021/AcWing1221_ManualHash.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
/*
|
||||
用桶计数的思路
|
||||
*/
|
||||
// Accepted 134 ms
|
||||
using namespace std;
|
||||
const int N = 5e6 + 10;
|
||||
int n;
|
||||
int bucket[N];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
memset(bucket, -1, sizeof bucket);
|
||||
|
||||
for (int c = 0; c * c <= n / 2; c++)
|
||||
for (int d = c; c * c + d * d <= n; d++) {
|
||||
int t = c * c + d * d;
|
||||
if (t > 5e6) continue;
|
||||
if (bucket[t] == -1) bucket[t] = c;
|
||||
}
|
||||
|
||||
for (int a = 0; a * a <= n / 4; a++) {
|
||||
for (int b = a; a * a + b * b <= n / 3; b++) {
|
||||
int t = n - a * a - b * b;
|
||||
int c = bucket[t];
|
||||
if (c == -1 || t > 5e6) continue;
|
||||
int d = sqrt(t - c * c);
|
||||
printf("%d %d %d %d\n", a, b, c, d);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user