QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740958 | #1196. Fun Region | Jose_17 | WA | 597ms | 6884kb | C++20 | 6.6kb | 2024-11-13 12:40:43 | 2024-11-13 12:40:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// Holi c:
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(), v.end()
const int Inf = 1e9;
const ll mod = 1e9+7;
const ll INF = 4e18;
using ld = long double;
const ld eps = 1e-6, inf = numeric_limits<ld>::max(), pi = acos(-1);
bool geq(ld a, ld b){return a-b >= -eps;}
bool leq(ld a, ld b){return b-a >= -eps;}
bool ge(ld a, ld b){return a-b > eps;}
bool le(ld a, ld b){return b-a > eps;}
bool eq(ld a, ld b){return abs(a-b) <= eps;}
bool neq(ld a, ld b){return abs(a-b) > eps;}
struct point{
ld x, y;
point(): x(0), y(0){}
point(ld x, ld y): x(x), y(y){}
point operator+(const point & p) const{return point(x + p.x, y + p.y);}
point operator-(const point & p) const{return point(x - p.x, y - p.y);}
point operator*(const ld & k) const{return point(x * k, y * k);}
point operator/(const ld & k) const{return point(x / k, y / k);}
point operator+=(const point & p){*this = *this + p; return *this;}
point operator-=(const point & p){*this = *this - p; return *this;}
point operator*=(const ld & p){*this = *this * p; return *this;}
point operator/=(const ld & p){*this = *this / p; return *this;}
point rotate(const ld & a) const{return point(x*cos(a) - y*sin(a), x*sin(a) + y*cos(a));}
point perp() const{return point(-y, x);}
ld ang() const{
ld a = atan2l(y, x); a += le(a, 0) ? 2*pi : 0; return a;
}
ld dot(const point & p) const{return x * p.x + y * p.y;}
ld cross(const point & p) const{return x * p.y - y * p.x;}
ld norm() const{return x * x + y * y;}
ld length() const{return sqrtl(x * x + y * y);}
point unit() const{return (*this) / length();}
bool operator==(const point & p) const{return eq(x, p.x) && eq(y, p.y);}
bool operator!=(const point & p) const{return !(*this == p);}
bool operator<(const point & p) const{return le(x, p.x) || (eq(x, p.x) && le(y, p.y));}
bool operator>(const point & p) const{return ge(x, p.x) || (eq(x, p.x) && ge(y, p.y));}
bool half(const point & p) const{return le(p.cross(*this), 0) || (eq(p.cross(*this), 0) && le(p.dot(*this), 0));}
};
istream &operator>>(istream &is, point & p){return is >> p.x >> p.y;}
ostream &operator<<(ostream &os, const point & p){return os << "(" << p.x << ", " << p.y << ")";}
int sgn(ld x){
if(ge(x, 0)) return 1;
if(le(x, 0)) return -1;
return 0;
}
point intersectLines(const point & a1, const point & v1, const point & a2, const point & v2){
//lines a1+tv1, a2+tv2
//assuming that they intersect
ld det = v1.cross(v2);
return a1 + v1 * ((a2 - a1).cross(v2) / det);
}
int intersectLineSegmentInfo(const point & a, const point & v, const point & c, const point & d){
//line a+tv, segment cd
point v2 = d - c;
ld det = v.cross(v2);
if(eq(det, 0)){
if(eq((c - a).cross(v), 0)){
return -1; //infinity points
}else{
return 0; //no point
}
}else{
return sgn(v.cross(c - a)) != sgn(v.cross(d - a)); //1: single point, 0: no point
}
}
vector<point> cutPolygon(const vector<point> & P, const point & a, const point & v){
//returns the part of the convex polygon P on the left side of line a+tv
int n = P.size();
vector<point> lhs;
for(int i = 0; i < n; ++i){
if(geq(v.cross(P[i] - a), 0)){
lhs.push_back(P[i]);
}
if(intersectLineSegmentInfo(a, v, P[i], P[(i+1)%n]) == 1){
point p = intersectLines(a, v, P[i], P[(i+1)%n] - P[i]);
if(p != P[i] && p != P[(i+1)%n]){
lhs.push_back(p);
}
}
}
return lhs;
}
vector<point> convexHull(vector<point> P){
sort(P.begin(), P.end());
vector<point> L, U;
for(int i = 0; i < P.size(); i++){
while(L.size() >= 2 && leq((L[L.size() - 2] - P[i]).cross(L[L.size() - 1] - P[i]), 0)){
L.pop_back();
}
L.push_back(P[i]);
}
for(int i = P.size() - 1; i >= 0; i--){
while(U.size() >= 2 && leq((U[U.size() - 2] - P[i]).cross(U[U.size() - 1] - P[i]), 0)){
U.pop_back();
}
U.push_back(P[i]);
}
L.pop_back();
U.pop_back();
L.insert(L.end(), U.begin(), U.end());
return L;
}
vector<point> funPolygon(vector<point> P, int i1){
int n = P.size();
vector<point> res, ans;
set<point> aux;
res.pb(P[i1]); aux.insert(P[i1]); res.pb(P[(i1 + 1) % n]); aux.insert(P[(i1 + 1) % n]);
int i = (i1 + 2) % n;
bool fl = false;
while(1){
int k = res.size();
if(!fl){
if(aux.find(P[i]) != aux.end() && i != i1){
bool fla = false;
for(int j = 0; j < k; j++){
if(res[j] == P[i]) fla = true;
if(fla) ans.pb(res[j]);
}
break;
}
if(geq((res[k - 1] - res[k - 2]).cross(P[i] - res[k - 2]), 0)){
res.pb(P[i]); aux.insert(P[i]);
i = (i + 1) % n;
}else{
fl = true;
}
}else{
auto u = intersectLineSegmentInfo(res[k - 2], res[k - 1] - res[k - 2], P[i], P[(i + 1) % n]);
if(u == 1){
auto it = intersectLines(res[k - 2], res[k - 1] - res[k - 2], P[i], P[(i + 1) % n] - P[i]);
if(it != P[(i + 1) % n]){
if(it == P[i]) res.pb(P[i]), aux.insert(P[i]);
else res.pb(it), aux.insert(it);
fl = false;
}
}else if(u == -1){
res.pb(P[i]); aux.insert(P[i]);
fl = false;
}
i = (i + 1) % n;
}
}
ans = convexHull(ans);
return ans;
}
vector<point> intersectPolygons(vector<point> A, vector<point> B){
int n = B.size();
for(int i = 0; i < n; i++){
A = cutPolygon(A, B[i], B[(i + 1) % n] - B[i]);
}
return A;
}
ld area(vector<point> & P){
int n = P.size();
ld ans = 0;
for(int i = 0; i < n; i++){
ans += P[i].cross(P[(i + 1) % n]);
}
return abs(ans / 2);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n; cin>>n;
vector<point> P(n);
for(int i = 0; i < n; i++){
int a, b; cin>>a>>b;
P[i] = point(a, b);
}
vector<vector<point>> Ps;
for(int i = 0; i < n; i++){
auto v = funPolygon(P, i);
//cout<<P[i]<<" -> ";
//for(auto d : v) cout<<d<<" "; cout<<'\n';
if(v.size() > 2) Ps.pb(v);
}
sort(all(Ps));
Ps.erase(unique(all(Ps)), Ps.end());
for(auto d : Ps){
//for(auto e : d) cout<<e<<" ";
//cout<<area(d);
//cout<<'\n';
}
auto ans = Ps[0];
for(int i = 1; i < Ps.size(); i++){
ans = intersectPolygons(ans, Ps[i]);
}
cout<<setprecision(25)<<area(ans);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3792kb
input:
4 10 0 20 10 10 30 0 10
output:
300
result:
ok found '300.0000000', expected '300.0000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
10 145 269 299 271 343 193 183 139 408 181 356 324 176 327 147 404 334 434 102 424
output:
12658.31301913107456158514
result:
ok found '12658.3130191', expected '12658.3130191', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
6 144 401 297 322 114 282 372 178 197 271 368 305
output:
0
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 597ms
memory: 4628kb
input:
2000 9274 7020 6000 7020 6000 7030 8801 7030 8801 7040 6000 7040 6000 7050 6517 7050 6517 7060 6000 7060 6000 7070 6182 7070 6182 7080 6000 7080 6000 7090 9928 7090 9928 7100 6000 7100 6000 7110 8928 7110 8928 7120 6000 7120 6000 7130 7778 7130 7778 7140 6000 7140 6000 7150 8627 7150 8627 7160 6000 ...
output:
80000.0000000000009094947
result:
ok found '80000.0000000', expected '80000.0000000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3964kb
input:
32 6000 9970 8929 9970 8929 9980 6000 9980 6000 9990 8806 9990 8806 10000 4000 10000 4000 60 3819 50 3819 40 4000 40 4000 30 323 30 323 20 4000 20 4000 10 1367 10 1367 0 6000 0 6000 9910 6139 9910 6139 9920 6000 9920 6000 9930 8225 9930 8225 9940 6000 9940 6000 9950 9296 9950 9296 9960 6000 9960
output:
19760000
result:
ok found '19760000.0000000', expected '19760000.0000000', error '0.0000000'
Test #6:
score: -100
Wrong Answer
time: 184ms
memory: 6884kb
input:
1859 2843 492 2851 488 2866 481 2909 461 2940 447 2964 436 2975 431 2987 425 2995 422 2998 421 2999 420 3040 403 3054 397 3059 395 3059 394 3066 392 3073 389 3075 387 3076 388 3078 386 3092 381 3109 373 3126 367 3134 364 3145 359 3149 358 3163 352 3173 348 3174 348 3180 345 3203 336 3211 333 3217 33...
output:
29790850.75
result:
wrong answer 1st numbers differ - expected: '2079546.0000000', found: '29790850.7500000', error = '13.3256512'