QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646197#7906. Almost Convexfrankly6TL 0ms0kbC++202.1kb2024-10-16 21:40:082024-10-16 21:40:08

Judging History

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

  • [2024-10-16 21:40:08]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-16 21:40:08]
  • 提交

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
    {
        // return (x-px)*(a.y-py)-(y-py)*(a.x-px)>0;
        ld t1=atan2(y-py,x-px);
        ld t2=atan2(a.y-py,a.x-px);
        // cout << "t1=" << t1 << ", t2=" << t2 << '\n';
        return t1<t2;
    }
}p[MX], np[MX], s1[MX];
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;
    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';
        int id=np[i].id;
        if(ins[id]) continue;
        py=np[i].y, px=np[i].x;
        sort(p+1,p+1+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 << ans+1 << '\n';
    return (0-0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

7
1 4
4 0
2 3
3 1
3 5
0 0
2 4

output:


result: