HDU 6325 Problem G. Interstellar Travel [凸包]

题意

给你n个点,求一个序列p1,p2,..pm,使得其相邻两个点到原点的向量的叉乘和最小,若两个序列答案相同,那么输出字典序最小的序列。

题解

可以很容易的得出,最后围成的形状是一个上凸包,因此我们维护一个上凸包,由于存在重点与三点共线的情况,那么对于重点,我们只取id最小的点就可以了。对于三点共线的话,那么对于这一段共线的点,两端的端点肯定必须要取,对于中间的情况,我们只需要从后往前维护一个递减序列即可。

AC代码

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<stack>
#define N 200005
using namespace std;
typedef long long ll;
vector<ll>ans,gg;
stack<ll>sta;
struct point
{
    ll x,y,id;
    point(){}
    point(ll x,ll y)
    {
        this->x=x;
        this->y=y;
    }
}p[N],tubao[N];
ll mark[N];
point operator-(point A,point B)  
{  
    return point(A.x-B.x,A.y-B.y);  
}  
bool cmp(point a,point b)
{
    if(a.x==b.x)
    {
        if(a.y==b.y)return a.id<b.id; 
        return a.y<b.y;
    }
    return a.x<b.x;
}
ll Cross(point A,point B)  
{  
    return A.x*B.y-A.y*B.x;  
}  
ll ConvexHull(point* p,ll n,point* ch) 
{  
    ll m=0; 
    for(ll i=0;i<n;i++)
    {  
        if(mark[i])continue;
        while(m>=2&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])>0)m--;  
        ch[m++]=p[i];  
    }    
    return m;  
}  
int main()
{
    ll T;
    scanf("%lld",&T);
    while(T--)
    {
        memset(mark,0,sizeof(mark));
        ans.clear();
        ll n;
        scanf("%lld",&n);
        for(ll i=0;i<n;i++)
            scanf("%lld%lld",&p[i].x,&p[i].y),p[i].id=i+1;
        sort(p,p+n,cmp);
        for(int i=1;i<n;i++)
            if(p[i].x==p[i-1].x&&p[i].y==p[i-1].y)
                mark[i]=1;
        ll tot=ConvexHull(p,n,tubao);
        for(ll i=0;i<tot;i++)
        {
            ans.push_back(tubao[i].id);
            while(i<tot-2&&Cross(tubao[i+1]-tubao[i],tubao[i+2]-tubao[i])==0)
                gg.push_back(tubao[i+1].id),i++;
            ll now=tubao[i+1].id;
            for(int j=gg.size()-1;j>=0;j--)
                if(gg[j]<now)
                    sta.push(gg[j]),now=gg[j];
            gg.clear();
            while(!sta.empty())
            {
                ans.push_back(sta.top());
                sta.pop();
            }
        }
        for(int i=0;i<ans.size()-1;i++)
            printf("%lld ",ans[i]);
        printf("%lld\n",ans[ans.size()-1]);
    }

}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
How should we use data to help us analyse our beliefs? This book is concerned with the subjectivist analysis of uncertainty, and develops methods that combine prior judgements with information derived from relevant data. Whenever we move from broadly data-focused questions, such as ‘Does this data set suggest that a certain medical treatment is likely to be effective?’, to broadly decision-motivated questions, such as ‘Are we sufficiently confident, given all that we know about this treatment, to recommend its widespread use?’, then we must make such a synthesis of data with more generalized forms of information. Because we may find this hard to achieve, we need some methodology to help us. This methodology should be clear, helpful, logically well founded and tractable. The Bayesian approach to statistics is the natural methodology for this purpose. This approach treats all uncertainties within a common probabilistic framework, combining the different sources of information using the rules of probability. This approach has a sound logical foundation and a well-developed methodology and is popular and successful in many areas of application. However, in large-scale applications, the Bayesian approach can easily become the victim of its own ambition. Representing all uncertainties in probabilistic form is a daunting task for complicated problems. This is partly because of the intrinsic difficulties in judging the value of each relevant source of knowledge. However, in large part, the task is difficult because the Bayesian approach requires us to specify our uncertainties to an extreme level of detail. In practice, it is usually beyond our ability to make meaningful specifications for our joint probability distributions for multiple outcomes. If we do wish to follow a broadly Bayesian path, then we must either choose to make specifications that do not correspond to our actual uncertainties or be more modest about our ability to render our beliefs in probabilistic form. If the data are plentiful and unambiguous in their message or if the problem is not sufficiently important to merit careful analysis, then little harm is done by somewhat misrepresenting our beliefs. However, when the issue is important and data are less plentiful, then we must be more careful and honest. When we cannot make full belief specifications, we require alternative methods that respect the limitations on our abilities to specify meaningful beliefs and allow us to conduct partial analyses strictly in terms of the actual limited aspects of our beliefs that we are able to specify.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值