QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#646199#7906. Almost Convexfrankly6TL 0ms4312kbC++202.0kb2024-10-16 21:40:322024-10-16 21:40:32

Judging History

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

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

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()
{
    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);
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 4312kb

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: 4264kb

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: 4088kb

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 4156kb

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: 4256kb

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...

output:


result: