QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749504 | #5426. Drain the Water Tank | Sesquipedalian | WA | 0ms | 3708kb | C++20 | 6.0kb | 2024-11-15 02:11:36 | 2024-11-15 02:11:38 |
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)%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]);
// cout << miny << endl;
// cout << i << ' ' << j << endl;
if(miny==y[i])
{
if(x[j]==x[(j+1)%n])
{
if(x[i]<x[(j+1)%n]) 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)%n]) 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;
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]);
// cout << miny << endl;
// cout << i << ' ' << j << endl;
if(miny==y[i])
{
if(x[j]==x[(j+1)%n])
{
if(x[i]<x[(j+1)%n]) 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)%n]) 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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: 3600kb
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: 3524kb
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: 3644kb
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: 0
Accepted
time: 0ms
memory: 3656kb
input:
8 0 0 1 0 3 -1 3 0 1 1 4 1 5 0 3 4
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
5 0 0 170 0 140 30 60 30 0 70
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
5 0 0 170 0 140 30 60 30 0 100
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
5 0 0 1 2 1 5 0 2 0 1
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
3 0 0 100 0 0 100
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
3 200 0 100 100 0 0
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
3 50 50 100 50 100 100
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
3 3 0 0 4 0 0
output:
1
result:
ok 1 number(s): "1"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
3 10000 10000 -10000 10000 10000 9999
output:
1
result:
ok 1 number(s): "1"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
3 10000 10000 -10000 10000 10000 9900
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
3 10000 10000 9999 10000 10000 -10000
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
3 0 0 200 0 100 173
output:
1
result:
ok 1 number(s): "1"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 0 0 200 0 100 1
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
3 -10000 -10000 10000 9999 9999 10000
output:
1
result:
ok 1 number(s): "1"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
4 10 10 20 10 20 20 10 20
output:
1
result:
ok 1 number(s): "1"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
4 -10000 -10000 10000 -10000 10000 10000 -10000 10000
output:
1
result:
ok 1 number(s): "1"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
4 100 0 200 100 100 200 0 100
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
4 0 1 100 0 101 100 1 101
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
4 0 0 100 0 100 50 0 50
output:
1
result:
ok 1 number(s): "1"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
4 0 0 50 0 50 100 0 100
output:
1
result:
ok 1 number(s): "1"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
4 0 10 10 0 100 90 90 100
output:
1
result:
ok 1 number(s): "1"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
8 0 100 100 0 250 0 350 100 350 250 250 350 100 350 0 250
output:
1
result:
ok 1 number(s): "1"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
6 0 50 10 0 70 0 80 10 70 50 50 80
output:
1
result:
ok 1 number(s): "1"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
4 0 100 0 0 100 0 20 20
output:
1
result:
ok 1 number(s): "1"
Test #29:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
4 0 100 55 55 100 0 100 100
output:
1
result:
ok 1 number(s): "1"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
8 0 0 100 0 100 20 40 20 40 40 100 40 100 60 0 60
output:
1
result:
ok 1 number(s): "1"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
12 0 0 90 0 90 30 40 30 40 40 90 40 90 50 0 50 0 20 50 20 50 10 0 10
output:
1
result:
ok 1 number(s): "1"
Test #32:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
12 0 0 100 0 100 100 10 100 10 110 200 110 200 60 101 60 101 40 210 40 210 120 0 120
output:
2
result:
ok 1 number(s): "2"
Test #33:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
10 1000 0 1100 0 1200 100 1220 200 1200 110 1100 10 1000 10 900 110 880 200 900 100
output:
1
result:
ok 1 number(s): "1"
Test #34:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
16 0 0 60 0 60 70 0 70 0 20 40 20 40 50 20 50 20 40 30 40 30 30 10 30 10 60 50 60 50 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #35:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
8 0 1 100 0 5 5 200 5 105 0 205 1 205 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #36:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
8 0 1 50 0 5 5 200 5 150 0 205 1 205 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #37:
score: -100
Wrong Answer
time: 0ms
memory: 3708kb
input:
9 99 100 100 100 99 99 301 99 300 100 301 100 201 274 200 273 199 274
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'