QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#756267 | #6676. Computational Geometry | diguo | AC ✓ | 20ms | 4696kb | C++20 | 2.5kb | 2024-11-16 19:36:42 | 2024-11-16 19:36:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = x; i <= y; ++i)
#define per(i, x, y) for (int i = x; i >= y; --i)
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pil pair<int, ll>
#define all(x, y) x.begin() + y, x.end()
inline ll read()
{
ll x = 0, f = 1; char ch = getchar();
while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
while (isdigit(ch)) {x = x * 10 + ch - 48; ch = getchar();}
return x * f;
}
void solve()
{
int n = read(), k = read();
vector<int> x(n), y(n);
rep(i, 0, n - 1) x[i] = read(), y[i] = read();
double s = 0;
deque<int> q;
auto cal = [&](int u, int v)
{
return 1ll * x[u] * y[v] - 1ll * x[v] * y[u];
};
if (n == 3)
{
double ans = abs(cal(0, 1) + cal(1, 2) + cal(2, 0)) / 2.0;
printf("%.1lf", ans);
return;
}
auto add = [&](int i)
{
// cout << "add " << i << '\n';
if (q.empty() || q.size() == 1) q.push_back(i);
else
{
int l = q.front(), r = q.back();
s += abs(cal(l, r) + cal(r, i) + cal(i, l)) / 2.0;
q.push_back(i);
}
};
auto del = [&]()
{
// cout << "del " << q.front() << '\n';
if (q.size() <= 2) q.pop_front();
else
{
int lst = q.front();
q.pop_front();
int l = q.front(), r = q.back();
s -= abs(cal(lst, l) + cal(l, r) + cal(r, lst)) / 2.0;
}
};
rep(i, 0, k - 1) add(i);
int now = k - 1;
double ans = 0;
rep(i, 0, n - 1)
{
now = (now + 1) % n;
add(now);
int l = 0, r = n - k;
auto get = [&](int add) -> double
{
int x = (q.back() + add) % n;
ll ret = cal(q.front(), q.back()) + cal(q.back(), x) + cal(x, q.front());
return abs(ret) / 2.0;
};
double t = 0;
while (l + 1 < r)
{
int mid = l + r >> 1;
double a1 = get(mid - 1), a2 = get(mid + 1);
if (a1 < a2) t = max(t, a2), l = mid;
else t = max(t, a1), r = mid;
}
// printf("%d %.1lf %.1lf\n", i, s, t);
t = max({t, get(l), get(r)});
ans = max(ans, s + t);
del();
}
printf("%.1lf", ans);
}
int main()
{
int t = read();
while (t--)
{
solve();
if (t) putchar('\n');
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3868kb
input:
3 3 1 0 0 1 0 0 1 8 3 1 2 3 1 5 1 7 3 8 6 5 8 3 7 1 5 7 2 3 6 1 1 3 1 7 1 8 1 5 6 4 6
output:
0.5 26.5 20.0
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3960kb
input:
1 4 2 -1000000000 -1000000000 1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000
output:
4000000000000000000.0
result:
ok found '4000000000000000000.000000000', expected '4000000000000000000.000000000', error '0.000000000'
Test #3:
score: 0
Accepted
time: 12ms
memory: 3680kb
input:
14246 7 5 -999999980 -999999988 -999999979 -999999984 -999999978 -999999978 -999999979 -999999972 -1000000000 -999999998 -999999993 -1000000000 -999999984 -999999993 6 1 -999999987 -999999987 -999999993 -999999981 -999999998 -999999986 -1000000000 -999999996 -999999995 -1000000000 -999999986 -999999...
output:
230.5 78.0 173.0 46.0 161.5 25.0 224.0 78.0 42.0 75.0 113.5 179.0 227.0 224.5 459.5 33.5 323.0 208.0 14.0 117.0 261.5 162.5 136.0 227.5 91.0 376.0 81.0 502.5 179.5 141.0 346.5 41.0 90.5 209.0 118.0 183.0 406.5 49.5 80.5 222.5 394.0 243.0 114.0 402.0 245.5 386.0 106.0 75.0 297.5 424.0 269.0 104.0 216...
result:
ok 14246 numbers
Test #4:
score: 0
Accepted
time: 20ms
memory: 4000kb
input:
14244 6 4 -547850284 -481269250 -1000000000 -714647423 -533299247 -1000000000 656886478 -769438616 700263718 -430440203 106399420 -305601756 10 3 -466281822 506862192 -907094238 85058839 -1000000000 -281869646 -855490497 -478229011 -112167057 -1000000000 147495199 -983428035 704507845 -902383045 828...
output:
732791354437434368.0 1492466916906283520.0 1571608624804175360.0 853722168331793664.0 1841579555796118016.0 186812625650844480.0 1374931373816256768.0 1396248766527417344.0 300749428982044480.0 1597680977600300544.0 238431782745048672.0 1905621061870671360.0 1457051885738670592.0 772319614795252864....
result:
ok 14244 numbers
Test #5:
score: 0
Accepted
time: 14ms
memory: 3740kb
input:
1000 100 84 -638427072 -696806030 -574275620 -741577840 -517724956 -779879773 -440790977 -831653888 -371696794 -867523797 -292070733 -904513365 -246157947 -920874374 -196125497 -936669098 -120139525 -960537360 -54479671 -978537127 -11534554 -987883373 26411313 -994847568 72263671 -1000000000 1168709...
output:
2901829084045603328.0 327527198347053248.0 1734256029955228928.0 2416380865036325888.0 935891084317887488.0 2828414703961763840.0 2101460694807832832.0 2426931532374706176.0 2679372534658023424.0 2762361281720088576.0 1176864063012643840.0 2674175975267184128.0 415161195168528640.0 13157111226510325...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 16ms
memory: 3756kb
input:
100 1000 168 -808847262 -517721134 -803072067 -525448193 -798730847 -531136476 -796502549 -534032203 -791151313 -540928191 -786588703 -546785604 -782732315 -551644783 -780071973 -554976222 -774771946 -561591700 -769683918 -567839156 -769554831 -567997637 -766249149 -572042373 -759870835 -579831042 -...
output:
1028923552719995904.0 2832301779860074496.0 2848011247470066688.0 2506790184987357184.0 2622377875251075072.0 2556381233480029184.0 2780396909089778176.0 1735531899101324288.0 987263293126023808.0 2933858965189288960.0 1940748120157040384.0 2867130361573921280.0 2747069586277202944.0 275180739114962...
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 20ms
memory: 3868kb
input:
10 10000 3930 374998960 871320826 374305646 871707307 373541784 872131442 372913079 872480119 372247815 872848960 372082544 872940283 371300533 873371391 370696772 873703715 369897687 874143282 369135422 874562333 368787728 874753324 368396307 874968013 367915968 875230945 367376687 875525844 367147...
output:
2095908706043764224.0 2881509906421580288.0 860651843537663872.0 2225240521612311808.0 911084696371304704.0 2134470965837803520.0 2924168382633125888.0 1052994530795952640.0 2555680635181536256.0 2703241471286157312.0
result:
ok 10 numbers
Test #8:
score: 0
Accepted
time: 20ms
memory: 4696kb
input:
1 100000 91077 937469288 -231959258 937491476 -231891836 937502721 -231857664 937522226 -231798381 937545631 -231727224 937556752 -231693411 937581626 -231617767 937594048 -231579990 937605611 -231544822 937620487 -231499574 937644936 -231425160 937656870 -231388830 937680141 -231317975 937699154 -2...
output:
2889987064399290880.0
result:
ok found '2889987064399290880.000000000', expected '2889987064399269888.000000000', error '0.000000000'