QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#721637 | #5426. Drain the Water Tank | Calculatelove# | WA | 0ms | 3796kb | C++14 | 2.2kb | 2024-11-07 16:30:21 | 2024-11-07 16:30:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define db double
#define ll long long
#define N 2010<<1
int n;
int nxt[N];
bool b[N];
const db eps=1e-10;
struct node{
db x,y;
node(){}
node(db _x,db _y):x(_x),y(_y){}
node operator-(const node &t)const {return {x-t.x,y-t.y};}
bool operator==(const node &t) const {return x==t.x&&y==t.y;}
}e[N];
db cross(node a,node b) {
return a.x*b.y-b.x*a.y;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>e[i].x>>e[i].y;
for(int i=n+1;i<=2*n;i++) e[i]=e[i-n];
nxt[2*n]=2*n;
for(int i=2*n-1;i>=1;i--) {
if(e[i].y==e[i+1].y) nxt[i]=nxt[i+1];
}
int ans=0;
for(int i=n;i<2*n;i++) {
int s=0;
for(int j=1;j<=n;j++) {
node c=e[j],d=e[j+1];
if(c==e[i] || d==e[i]) continue;
if(c.x==e[i].x || d.x==e[i].x) continue;
if(c.x>d.x) swap(c,d);
if(cross(d-e[i],c-e[i])<=0) continue;
if(e[i].x>min(c.x,d.x) && e[i].x<max(c.x,d.x)) s++;
}
for(int j=1;j<=n;j++) {
if(j==i) continue;
if(e[i].x!=e[j].x) continue;
if(e[j].y<=e[i].y) continue;
node c=e[(j-1==0?n:j-1)],d=e[j+1];
db g=cross(c-e[i],e[j]-e[i]),h=cross(d-e[i],e[j]-e[i]);
if(fabs(g*h)<eps) {
if(c.x==e[i].x && d.x==e[i].x) continue;
s++;
}
else {
if(g*h>eps) {
s+=2;
}
else {
s++;
}
}
}
// cout<<i<<" "<<s<<endl;
if(s&1) b[i]=1;
}
// for(int i=n;i<=2*n;i++) cout<<b[i]<<" ";cout<<endl;
for(int i=n;i<2*n;i++) {
if(!b[i]) continue;
if(e[i].y<e[i-1].y && e[i].y<e[i+1].y) ans++;//,cout<<(i-n==0?n:i-n)<<endl;
}
// cout<<ans<<endl;
for(int i=n;i<2*n;i++) {
if(nxt[i]+1>2*n) continue;
if(nxt[i]==i) continue;
if(e[i].y<e[i-1].y && e[i].y<e[nxt[i]+1].y) ans++;
}
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
input:
6 0 0 1 1 2 1 3 0 3 2 0 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
8 4 4 0 4 0 2 1 2 2 2 2 0 3 0 4 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
7 1 0 3 4 0 3 1 2 2 3 1 1 0 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3788kb
input:
6 0 0 2 0 1 1 4 1 5 0 3 4
output:
0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'