2021AutoX安途杯中山大学程序设计校赛 I Lucky Numbers ABCD(构造)
Solution
等式 [ k ∗ x ] ∗ [ ( k + 1 ) ∗ ( x + 1 ) ] = [ ( k + 1 ) ∗ x ] ∗ [ k ∗ ( x + 1 ) ] [k*x]*[(k+1)*(x+1)]=[(k+1)*x]*[k*(x+1)] [k∗x]∗[(k+1)∗(x+1)]=[(k+1)∗x]∗[k∗(x+1)]
只需要找到 k,x 即可。
令 x 等于 sqrt(n),找到 k 即可。
我试了直接取
n
,
n
+
1
,
n
−
2
,
n
−
1
\sqrt n,\sqrt {n+1},\sqrt{n-2},\sqrt{n-1}
n,n+1,n−2,n−1,但是wa了好几发,极其玄学。。 (不愧是你,浮点数)
代码
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
//#define int long long
#define lowbit(x) ((x) & (-x))
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef pair<double, int> pdi;
typedef double dd;
typedef long long ll;
const int MAXN = 1010;
const int MAXM = 3000010;
const dd eps = 1e-6;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
int main()
{
int t;
cin >> t;
while(t--)
{
ll n;
cin >> n;
ll x = (ll)sqrt(n);
ll t = (n - 3 * sqrt(n)) / x;
while (x * t <= (n - 3 * sqrt(n)))
t++;
printf("%lld %lld %lld %lld\n", x * t, (x + 1) * t, (t + 1) * x, (x + 1) * (t + 1));
}
}
总结
比赛时取了左右端点和其的两倍和 1/2 倍,wa了一发发现有可能低于下界。。