QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#749500 | #5426. Drain the Water Tank | Sesquipedalian | WA | 0ms | 3704kb | C++20 | 3.7kb | 2024-11-15 01:55:42 | 2024-11-15 01:55:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3+10;
ll x[N],y[N];
ll kk(ll x1,ll y1,ll x2,ll y2)
{
if(y1==y2) return 0;
else if(y1>y2) return -1;
else return 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
ll i,j;
for(i=0;i<n;i++)
{
cin >> x[i] >> y[i];
}
ll k1,k2;
ll sta=0;
k1=kk(x[sta],y[sta],x[sta+1],y[sta+1]);
while(k1==0&&sta<n)
{
sta++;
k1=kk(x[sta],y[sta],x[sta+1],y[sta+1]);
}
i=sta;j=i+1;
k2=kk(x[j],y[j],x[(j+1)%n],y[(j+1)%n]);
while(k2==0&&j!=sta)
{
j++;
j%=n;
k2=kk(x[j],y[j],x[(j+1)%n],y[(j+1)%n]);
}
// cout << i << ' ' << j << endl;
ll ans=0;
// ans++判断条件
// if(k1==-1&&k2==1)
// {
// if(x[i+1]<x[j]) ans++;
// else if(x[i+1]==x[j])
// {
// ans++;
// }
// }
i=j;
k1=k2;
j++;
j%=n;
if(i!=sta)
{
k2=kk(x[j],y[j],x[(j+1)%n],y[(j+1)%n]);
while(k2==0&&j!=sta)
{
j++;
j%=n;
k2=kk(x[j],y[j],x[(j+1)%n],y[(j+1)%n]);
}
j%=n;
// cout << i << ' ' << j << endl;
while(i!=sta)
{
// cout << i << ' ' << j << endl;
// ans++判断条件
if(k1==-1&&k2==1)
{
if(x[(i+1)%n]<x[j]) ans++;
else if(x[(i+1)%n]==x[j])
{
//x[i],y[i],x[i+1],y[i+1] x[j],y[j],x[j+1],y[j+1];
ll miny=min(y[i],y[(j+1)%n]);
if(miny==y[i])
{
if(x[j]==x[(j+1)%n])
{
if(x[i]<x[j+1]) ans++;
}
else
{
double xx;
if(x[(j+1)%n]>x[j])
{
xx=miny*(x[(j+1)%n]-x[j])*1.0/(y[(j+1)%n]-y[i]);
}
else
{
xx=miny*(x[(j+1)%n]-x[j])*1.0/(y[(j+1)%n]-y[i]);
xx=x[j]-xx;
}
if(x[i]<xx) ans++;
}
}
else
{
if(x[i]==x[(i+1)%n])
{
if(x[i]<x[j+1]) ans++;
}
else
{
double xx;
if(x[(i+1)%n]>x[i])
{
xx=miny*(x[i]-x[(i+1)%n])*1.0/(y[i]-y[(i+1)%n]);
}
else
{
xx=miny*(x[i]-x[(i+1)%n])*1.0/(y[i]-y[(i+1)%n]);
xx=x[(i+1)%n]-xx;
}
if(xx<x[(j+1)%n]) ans++;
}
}
}
}
i=j;
k1=k2;
j++;
j%=n;
k2=kk(x[j],y[j],x[(j+1)%n],y[(j+1)%n]);
while(k2==0&&j!=sta)
{
j++;
j%=n;
k2=kk(x[j],y[j],x[(j+1)%n],y[(j+1)%n]);
}
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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: 3664kb
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: 3532kb
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: 0
Accepted
time: 0ms
memory: 3536kb
input:
6 0 0 2 0 1 1 4 1 5 0 3 4
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3704kb
input:
8 0 0 1 0 3 -1 3 0 1 1 4 1 5 0 3 4
output:
1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'