QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618006#7906. Almost Convexlmz20050701Compile Error//C++204.3kb2024-10-06 18:03:402024-10-06 18:03:41

Judging History

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

  • [2024-10-06 18:03:41]
  • 评测
  • [2024-10-06 18:03:40]
  • 提交

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 dd;
};

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

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

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);
        t.dd=ddis({p[y].fir-p[x].fir,p[y].sec-p[x].sec})*ddis({i.fir-p[y].fir,i.sec-p[y].sec});
        //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<<' ';
        t.dd=ddis({p[y].fir-p[x].fir,p[y].sec-p[x].sec})*ddis({i.fir-p[x].fir,i.sec-p[x].sec});
        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++;
        }
    }
    while(j>=v2.size())
    {
        if(v1[v1.size()-1].pos==v2[j].pos)
        {
            ans++;
            break;
        }
        j++
    }
    return ans;
}

signed main()
{
    //cout<<getang({0,0},{0,1000*10000},{0,0},{0,100001*10000});
    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

answer.code: In function ‘long long int slove(long long int, long long int)’:
answer.code:145:12: error: expected ‘;’ before ‘}’ token
  145 |         j++
      |            ^
      |            ;
  146 |     }
      |     ~