QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#647510 | #7906. Almost Convex | frankly6 | WA | 536ms | 6380kb | C++20 | 2.4kb | 2024-10-17 14:31:17 | 2024-10-17 14:31:18 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef double ld;
typedef pair<int,int> PII;
const int MX=2020;
int N, cnt;
bool ins[MX];
bool vis[MX][MX];
int read()
{
int r=0, f=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
return r*f;
}
ld py, px;
struct point
{
ld x, y; int id;
point operator - (const point &a)const {return {x-a.x,y-a.y,id};}
point operator + (const point &a)const {return {x+a.x,y+a.y,id};}
ld operator ^ (const point &a)const {return x*a.y-y*a.x;}
bool operator < (const point &a)const
{
ld t1=atan2(y-py,x-px);
ld t2=atan2(a.y-py,a.x-px);
return t1<t2;
}
}p[MX], np[MX], s1[MX], pd;
int qua(point p)
{
return (p.y>0)*2+(p.x*p.y<0)+(p.y==0&&p.x<0)*3+(p.y==0&&p.x>0);
}
bool cmp(point a, point b)
{
if(qua(a-pd)!=qua(b-pd)) return qua(a-pd)<qua(b-pd);
else return ((a-pd)^(b-pd))>0;
}
int t1;
int main()
{
// freopen("testdata.in","r",stdin);
N=read(); int id=1;
for(int i=1;i<=N;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].id=i;
if(p[i].x<p[id].x||(p[i].x==p[id].x&&p[i].y<p[id].y)) id=i;
}
swap(p[1],p[id]); py=p[1].y; px=p[1].x; pd=p[1];
sort(p+2,p+1+N);
// for(int i=1;i<=N;i++) cout << "(" << p[i].x << "," << p[i].y << "), "; cout << '\n';
s1[++t1]=p[1];
for(int i=2;i<=N;i++)
{
while(t1>=2&&((s1[t1]-s1[t1-1])^(p[i]-s1[t1]))<=0) t1--;
s1[++t1]=p[i];
}
for(int i=1;i<=t1;i++) ins[s1[i].id]=1;
s1[++t1]=p[1];
for(int i=1;i<t1;i++) vis[s1[i].id][s1[i+1].id]=1;
int ans=0;
memcpy(np,p,sizeof(p));
for(int i=1;i<=N;i++)
{
// if(i%100==0) cout << "i=" << i << ", N=" << N << '\n';
int id=np[i].id;
if(ins[id]) continue;
py=np[i].y, px=np[i].x; pd=np[i];
// cout << "pd=(" << pd.x << "," << pd.y << ")\n";
sort(p+1,p+1+N,cmp);
// for(int j=1;j<=N;j++) cout << "(" << p[j].x << "," << p[j].y << "), "; cout << '\n';
p[N+1]=p[1];
for(int j=1;j<=N;j++)
{
int nxt=(p[j+1].id==id)?p[j+2].id:p[j+1].id;
ans+=vis[p[j].id][nxt];
}
// cout << "i=" << i << ", ans=" << ans << '\n';
}
cout << ans+1 << '\n';
return (0-0);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4272kb
input:
7 1 4 4 0 2 3 3 1 3 5 0 0 2 4
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4192kb
input:
5 4 0 0 0 2 1 3 3 3 1
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3992kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4348kb
input:
6 0 0 3 0 3 2 0 2 1 1 2 1
output:
7
result:
ok 1 number(s): "7"
Test #5:
score: 0
Accepted
time: 1ms
memory: 6380kb
input:
4 0 0 0 3 3 0 3 3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 536ms
memory: 6312kb
input:
2000 86166 617851 383354 -277127 844986 386868 -577988 453392 -341125 -386775 -543914 -210860 -429613 606701 -343534 893727 841399 339305 446761 -327040 -218558 -907983 787284 361823 950395 287044 -351577 -843823 -198755 138512 -306560 -483261 -487474 -857400 885637 -240518 -297576 603522 -748283 33...
output:
705
result:
wrong answer 1st numbers differ - expected: '718', found: '705'