QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722107#5426. Drain the Water TankCalculatelove#WA 0ms3876kbC++142.5kb2024-11-07 17:51:072024-11-07 17:51:13

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 17:51:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3876kb
  • [2024-11-07 17:51:07]
  • 提交

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;
}
bool ck(int id) {
    if(e[id-1].x==e[id].x && e[id+1].x==e[id].x) return 0;
    if(e[id-1].x<=e[id].x && e[id+1].x>=e[id].x) return 1;
    return 0;  
}
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];
        else nxt[i]=i;
    }
    // for(int i=1;i<=2*n;i++) cout<<nxt[i]<<" ";cout<<endl;
    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++;
        }
        // cout<<i<<" "<<s<<endl;
        // cout<<endl;
        for(int j=n;j<2*n;j++) {
            if(j==i) continue;
            if(e[i].x!=e[j].x) continue;
            if(e[j].y<=e[i].y) continue;
            // cout<<j<<" "<<endl;
            node c=e[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(j==13) cout<<g<<" "<<h<<endl;
            if(g*h<-eps) 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(!ck(i)) continue;
        // cout<<1;
        // cout<<i<<endl;
        if(e[i].y<e[i-1].y && e[i].y<e[i+1].y) ans++;//,cout<<i<<endl;//,cout<<(i-n==0?n:i-n)<<endl;
    }
    // cout<<ans<<endl;
    for(int i=n;i<2*n;i++) {
        // if(!b[i]) continue;
        if(!ck(i)) continue;
        if(nxt[i]==i) continue;
        int id=nxt[i]+1==2*n+1?1:nxt[i]+1;
        if(e[i].y<e[i-1].y && e[i].y<e[id].y) ans++;//,cout<<i<<endl;
        // if(i==6+8) cout<<e[i].y<<" "<<e[i-1].y<<" "<<
    }
    cout<<ans<<endl;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3876kb

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: 3772kb

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: 3776kb

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: 3768kb

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'