QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646044 | #7906. Almost Convex | frankly6 | TL | 1ms | 3952kb | C++17 | 2.0kb | 2024-10-16 21:03:14 | 2024-10-16 21:03:15 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;
typedef long double ld;
typedef pair<int,int> PII;
const int MX=2020;
const ld eps=1e-9;
int N, cnt;
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];
map<point,int> mp;
map<PII,int> ck;
int t1, t2;
using vec=point;
struct line {point p; vec v;};
int n1(int x){return x==t1?1:x+1;}
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;
sort(p+2,p+1+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++) mp[s1[i]]=1;
s1[++t1]=p[1];
for(int i=1;i<t1;i++) ck[make_pair(s1[i].id,s1[i+1].id)]=1;
int ans=0;
for(int i=1;i<=N;i++)
{
if(mp[p[i]]) continue;
py=p[i].y, px=p[i].x;
memcpy(np,p,sizeof(p));
swap(np[i],np[1]);
sort(np+2,np+N+1);
np[N+1]=np[2];
for(int j=2;j<=N;j++)
if(ck[make_pair(np[j].id,np[j+1].id)]) ans++;
// cout << "pi = (" << p[i].x << "," << p[i].y << "), 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: 3952kb
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: 3952kb
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: 3816kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3888kb
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: 0ms
memory: 3928kb
input:
4 0 0 0 3 3 0 3 3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Time Limit Exceeded
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...