QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617825#7906. Almost Convexlmz20050701WA 15ms8040kbC++203.8kb2024-10-06 17:16:252024-10-06 17:16:25

Judging History

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

  • [2024-10-06 17:16:25]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:8040kb
  • [2024-10-06 17:16:25]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define Fr(i,l,r) for(int i=l;i<=r;i++)
#define Fr_(i,a) for(auto i:a)
#define Fr_edge(i,x) for(int i=head[x];i!=0;i=edge[i].next)
#define memset(a,b) memset(a,b,sizeof(a));
#define pq priority_queue
#define addedge2(x,y,w) addedge(x,y,w),addedge(y,x,w)
#define new_opt friend bool operator
#define pb push_back
#define fastio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define pii pair<int,int>
#define fir first
#define sec second
#define pdd pair<double,double>
using namespace std;

const int N=2e6+10;
//const int N2=1e3+100;

int n=0;
pair<double,double> p[N];
int st[N];

double dis(int x,int y)
{
    return sqrt((p[x].fir-p[y].fir)*(p[x].fir-p[y].fir)+(p[x].sec-p[y].sec)*(p[x].sec-p[y].sec));
}

double cc(int a,int b,int c,int d)
{
    pair<double,double> A=make_pair(p[a].fir-p[b].fir,p[a].sec-p[b].sec);
    pair<double,double> B=make_pair(p[c].fir-p[d].fir,p[c].sec-p[d].sec);
    return A.fir*B.sec-A.sec*B.fir;
}
double Cross(pdd A, pdd B)
{
    return A.fir*B.sec-A.sec*B.fir; //A->B左转为正 
}
double Side(pdd a, pdd b, pdd p) //次栈顶元素a,栈顶元素b,新增点p 
{
    pdd A=pdd(b.fir-a.fir,b.sec-a.sec); //向量ab
    pdd B=pdd(p.fir-a.fir,p.sec-a.sec); //向量ap
    return Cross(A,B);
}
int tust()
{
    sort(p+1,p+n+1);
    st[0]=1,st[1]=2;
    int top=1;
    for (int i=3;i<=n;i++)//从p1开始的下凸包 
	{
        while(top&&Side(p[st[top-1]],p[st[top]],p[i])<=0)
            top--;
        st[++top]=i;
    }
    st[++top]=n-1;
    for(int i=n-2;i>=1;i--)//从pn开始的上凸包 
	{
        while(top&&Side(p[st[top-1]],p[st[top]],p[i])<=0)
            top--;
        st[++top]=i;
    }
    return top;
}

//---------------------------------------------------

vector<pdd> ba;
vector<pdd> fb;
int inst[N];

struct node
{
    pdd pos;
    double ang;
};

double ddis(pdd x)
{
    return sqrt(x.fir*x.fir+x.sec*x.sec);
}

double getang(pdd a,pdd b,pdd c,pdd e)
{
    pdd x={b.fir-a.fir,b.sec-a.sec};
    pdd y={e.fir-c.fir,e.sec-c.sec};
    return (x.fir*y.fir+x.sec*y.sec)/(ddis(x)*ddis(y));
}

bool cmp(node x,node y)
{
    return x.ang>y.ang;
}

int slove(int x,int y)
{
    if(fb.size()==0) return 0;
    //cout<<p[x].fir<<' '<<p[x].sec<<' '<<p[y].fir<<' '<<p[y].sec<<endl;
    int ans=0;
    vector<node> v1;
    Fr_(i,fb)
    {
        node t;
        t.pos=i;
        t.ang=getang(p[x],p[y],p[y],i);
        //cout<<t.ang<<' ';
        v1.pb(t);
    }
    //cout<<endl;
    sort(v1.begin(),v1.end(),cmp);

    vector<node> v2;
    Fr_(i,fb)
    {
        node t;
        t.pos=i;
        t.ang=getang(p[x],p[y],p[x],i);
        //cout<<t.ang<<' ';
        v2.pb(t);
    }
    //cout<<endl;
    sort(v2.begin(),v2.end(),cmp);

    int j=0;
    Fr(i,0,v1.size()-1)
    {
        if(v1[i].pos==v2[j].pos)
        {
            ans++;
            j++;
        }
    }
    return ans;
}

signed main()
{
    cin>>n;
    Fr(i,1,n)
    {
        cin>>p[i].fir>>p[i].sec;
    }
    int len_b=tust();
    //cout<<"size of st "<<len_b<<endl;

    Fr(j,1,len_b)
    {
        //cout<<st[i]<<endl;
        int i=j;
        if(p[st[i]]==p[st[i-1]]) continue;
        inst[st[i]]=1;
        ba.pb({p[st[i]].fir,p[st[i]].sec});
        //cout<<"in st "<<p[st[i]].fir<<' '<<p[st[i]].sec<<endl;
    }
    Fr(i,1,n)
    {
        if(inst[i]) continue;
        fb.pb({p[i].fir,p[i].sec});
        //cout<<"not in st  "<<p[i].fir<<' '<<p[i].sec<<endl;
    }

    //cout<<"size of fb "<<fb.size()<<endl;

    int ans=1;
    Fr(j,1,len_b-1)
    {
        int i=j;
        if(p[st[i]]==p[st[i-1]]) continue;
        ans+=slove(st[i],st[i+1]);
        //cout<<"in st "<<p[st[i]].fir<<' '<<p[st[i]].sec<<endl;
    }
    ans+=slove(st[len_b],st[1]);
    cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7804kb

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

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: 15ms
memory: 7876kb

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:

102

result:

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