QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617762#7906. Almost Convexlmz20050701WA 1ms7796kbC++203.6kb2024-10-06 16:58:452024-10-06 16:58:46

Judging History

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

  • [2024-10-06 16:58:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7796kb
  • [2024-10-06 16:58:45]
  • 提交

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 bao[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;
}

int tubao()
{
    n=unique(p+1,p+1+n)-p-1;
    sort(p+1,p+1+n);
    int ans=0;
    Fr(i,1,n)
    {
        while(ans>=2&&cc(bao[ans],bao[ans-1],i,bao[ans])<0) 
        {
            ans--;
        }
        bao[++ans]=i;
    }
    //ans--;
    int j=ans;
    
    for(int i=n;i>=1;i--)
    {
        while(ans>=j&&cc(bao[ans],bao[ans-1],i,bao[ans])<0) 
        {
            ans--;
        }
        bao[++ans]=i;
    }
    if(n==1) ans--;
    return ans;
}

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

vector<pdd> ba;
vector<pdd> fb;
int inbao[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=tubao()-1;
    //cout<<"size of bao "<<len_b<<endl;

    Fr(j,1,len_b)
    {
        //cout<<bao[i]<<endl;
        int i=j;
        if(p[bao[i]]==p[bao[i-1]]) continue;
        inbao[bao[i]]=1;
        ba.pb({p[bao[i]].fir,p[bao[i]].sec});
        //cout<<"in bao "<<p[bao[i]].fir<<' '<<p[bao[i]].sec<<endl;
    }
    Fr(i,1,n)
    {
        if(inbao[i]) continue;
        fb.pb({p[i].fir,p[i].sec});
        //cout<<"not in bao  "<<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[bao[i]]==p[bao[i-1]]) continue;
        ans+=slove(bao[i],bao[i+1]);
        //cout<<"in bao "<<p[bao[i]].fir<<' '<<p[bao[i]].sec<<endl;
    }
    ans+=slove(bao[len_b],bao[1]);
    cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7796kb

input:

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

output:

10

result:

wrong answer 1st numbers differ - expected: '9', found: '10'