QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647611#7906. Almost Convexfrankly6WA 310ms6008kbC++202.0kb2024-10-17 14:56:092024-10-17 14:56:10

Judging History

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

  • [2024-10-17 14:56:10]
  • 评测
  • 测评结果:WA
  • 用时:310ms
  • 内存:6008kb
  • [2024-10-17 14:56:09]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef pair<int,int> PII;
const int MX=2020;

int N, cnt;
bool ins[MX];
bool vis[MX][MX];
struct point;
int qua(point p);
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;
}
struct point
{
    int 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};}
    int operator ^ (const point &a)const {return x*a.y-y*a.x;}
}p[MX], np[MX], s1[MX], pd;
int qua(point p)
{
    if(p.x>=0&&p.y<0) return 1; 
    if(p.x>0&&p.y>=0) return 2;
    if(p.x<=0&&p.y>0) return 3;
    if(p.x<0&&p.y<=0) return 4;
    return 5;
}
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("%d%d",&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]); pd=p[1];
    sort(p+2,p+1+N,cmp);
    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++)
    {
        int id=np[i].id;
        if(ins[id]) continue;
        pd=np[i];
        sort(p+1,p+1+N,cmp);
        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: 100
Accepted
time: 1ms
memory: 3756kb

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

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: 1ms
memory: 5776kb

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

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

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: 310ms
memory: 6008kb

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:

33

result:

wrong answer 1st numbers differ - expected: '718', found: '33'