QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#796027 | #9808. Fragile Pinball | ucup-team3099# | WA | 1ms | 4076kb | C++23 | 6.2kb | 2024-12-01 06:33:08 | 2024-12-01 06:33:09 |
Judging History
answer
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <algorithm>
#include <iomanip>
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
struct PT {
typedef long double T;
T x, y;
PT(T _x = 0, T _y = 0) : x(_x), y(_y){}
PT operator +(const PT &p) const { return PT(x+p.x,y+p.y); }
PT operator -(const PT &p) const { return PT(x-p.x,y-p.y); }
PT operator *(T c) const { return PT(x*c,y*c); }
PT operator /(long double c) const { return PT(x/c,y/c); }
T operator *(const PT &p) const { return x*p.x+y*p.y; }
T operator %(const PT &p) const { return x*p.y-y*p.x; }
long double operator !() const { return hypotl(x, y); }
long double operator ^(const PT &p) const { return atan2l(*this%p, *this*p);}
friend std::ostream& operator << (std::ostream &os, const PT &p) {
return os << p.x << ' ' << p.y;
}
friend std::istream& operator >> (std::istream &is, PT &p) {
return is >> p.x >> p.y;
}
};
const long double eps = 1e-15;
int n;
long double ans[7];
template<class P>
P lineProj(P a, P b, P p, bool refl=false) {
P v = b - a;
return p - P(-v.y, v.x)*(1+refl)*(v % (p-a))/(v * v);
}
template<class P>
std::pair<int, P> lineInter(P s1, P e1, P s2, P e2) {
auto d = (e1 - s1) % (e2 - s2);
auto p = (e1 - s2) % (e2 - s2), q = (e2 - s2) % (s1 - s2);
return {1, (s1 * p + e1 * q) / d};
}
void go(std::vector<PT> hull, PT start, PT low, PT high, int bounces, int mask) {
for(int i = 0; i < n; i++) {
PT oriA = hull[i], oriB = hull[(i+1)%n];
int oriId = bounces % 2 == 0 ? i : (n - (i + 1)) % n;
PT A = oriA - start, B = oriB - start;
if(A % B <= -eps) {
continue;
}
PT newLow = low, newHigh = high;
if(low % A > 0) {
newLow = A;
}
if(B % high > 0) {
newHigh = B;
}
if(newLow % newHigh <= eps) {
continue;
}
ans[bounces] = std::max({ans[bounces],
!(lineInter(oriA, oriB, start, newLow + start).second - start),
!(lineInter(oriA, oriB, start, newHigh + start).second - start)
});
if(bounces + 1 <= n && (mask & (1 << oriId)) == 0) {
// std::cout << "at bounce " << bounces << " bouncing at index " << oriId << '\n';
// std::cout << newLow << ", " << newHigh << '\n';
// std::cout << "got distances " << (!(lineInter(oriA, oriB, start, newLow + start).second - start)) << ", " << (!(lineInter(oriA, oriB, start, newHigh + start).second - start)) << '\n';
// std::cout << "for points " << lineInter(oriA, oriB, start, newLow + start).second << ", " << lineInter(oriA, oriB, start, newHigh + start).second << '\n';
// std::cout << "original is " << oriA << ", " << oriB << '\n';
auto nxtHull = hull;
for(auto &p : nxtHull) {
p = lineProj(oriA, oriB, p, true);
}
std::reverse(nxtHull.begin() + 1, nxtHull.end());
// for(auto p : nxtHull) {
// std::cout << p << ' ';
// }
// std::cout << '\n';
go(nxtHull, start, newLow, newHigh, bounces+1, mask | (1 << oriId));
}
}
}
int main() {
std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
std::cin >> n;
std::vector<PT> hull(n);
for(int i = 0; i < n; i++) {
std::cin >> hull[i];
}
for(int i = 1; i <= n; i++) {
//std::cout << "starting for index " << i-1 << " which is " << hull[i%n] << '\n';
go(hull, hull[i%n], (hull[(i+1)%n] - hull[i%n]), (hull[(i-1)%n] - hull[i%n]), 0, 0);
}
std::cout << std::fixed << std::setprecision(20);
for(int i = 0; i <= n; i++) {
std::cout << ans[i] << (i == n ? '\n' : ' ');
}
}
/*
NEVER FORGET TO:
Look at the problem's constraints before coding.
How to cheese cf:
Find a lower bound or upper bound for the problem. Have faith that it is the answer of the problem.
If it isn't the answer, have more faith or change to another bound god by looking for a better bound.
Trust guesses. Who has time to think? If people in div2 AC the problem it requires no proof since people don't prove things.
You must draw cases. Thinking gets you nowhere, so draw cases and reach illogical conclusions from them.
Sometimes drawing cases is bad because it takes too much time. Faster is to not think at all and just code a bruteforce solution.
This is called "law of small numbers". If something works for small numbers, surely it works for big numbers.
https://en.wikipedia.org/wiki/Faulty_generalization#Hasty_generalization don't mind the "faulty" part of it, in competitive programming mistakes are lightly punished
Don't think about them being right or not, cf is a battle of intuition only.
Be as stupid as possible in implementation. Trying to be smart is an easy way to get WA.
Think about 2x2 cases for matrix problems and hope that everything works for the general case.
Find a necessary condition and trust it to be sufficient. They're basically the same thing.
Heuristics might speed up your code. Forget about complexity, it's only about ACing and not proving that your solution is good.
For paths in a grid starting at (1, i) or something like that, assume that they never cross and do D&C
Consider doing problems in reverse order of queries/updates
For combinatorics problems, consider symmetry
For problems that are similar to past problems, think about the differences betweem it and the current problem.
Sometimes the difference makes no difference. Sometimes it does.
General strategy (MUST DO):
Try to solve the problem with more restricted constraints.
About testing:
Test n=1, a[i]=1, a[i]=n, etc. Basically, test low values. No need to test if pretests are strong, but if you get WA it's good.
This isn't a joke. Do it if you get stuck. It's shit practice in my opinion, but do it if you want AC.
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4048kb
input:
3 4 0 0 3 0 -1
output:
5.00000000000000000000 8.00000000000000000000 8.86818503879756340601 12.21002481088195582796
result:
ok 4 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 4060kb
input:
3 4 0 0 3 0 2
output:
5.00000000000000000000 5.36656314599949527165 6.11191913849942517010 6.78220330441662831679
result:
ok 4 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 4076kb
input:
3 4 0 0 3 0 1
output:
5.00000000000000000000 6.18465843842649082469 7.19522354274454488138 8.65343949929425340205
result:
ok 4 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 4052kb
input:
3 62 -12 -48 100 -45 -96
output:
196.02295783912658835857 312.04173783276056028391 326.27847771877617755187 452.80712372911078536508
result:
ok 4 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 4004kb
input:
3 90 99 -76 -57 99 84
output:
227.79815626997510885632 274.35230645776344957087 306.89177947709210375615 330.10518554643359467882
result:
ok 4 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
3 -67 22 -86 12 -81 -12
output:
36.76955262170047127046 39.56397500565403616002 50.91685591710600820511 72.27758551745063941851
result:
ok 4 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 4056kb
input:
3 71 -48 -81 2 -83 -44
output:
160.01249951175689324734 308.05679456756879500134 308.05679456756879494583 308.05679456756879494583
result:
ok 4 numbers
Test #8:
score: 0
Accepted
time: 0ms
memory: 3992kb
input:
3 44 -44 -31 -77 8 -98
output:
81.93900170248597799455 115.79266829979315255039 125.60604402992012824936 167.93649349697933670367
result:
ok 4 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
3 40 91 -42 90 -5 -99
output:
195.25624189766635985244 378.87426679199884818616 378.87426679199884821392 378.87426679199884818616
result:
ok 4 numbers
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 4008kb
input:
4 -10 -97 13 -98 90 50 42 97
output:
200.84820138602187641896 269.68734146533457932127 382.16606804049615697672 476.59926283039679295594 474.67094164580517920426
result:
wrong answer 5th numbers differ - expected: '476.5992628', found: '474.6709416', error = '0.0040460'