zoukankan      html  css  js  c++  java
  • bzoj1091

    题解:

    暴力枚举顺序

    然后计算几何

    代码:

    #include<bits/stdc++.h>
    int n,id[11],lp=0;
    double v1,v2,ans=1e10;
    struct pos
    {
        double x,y;
        void init(){scanf("%lf%lf",&x,&y);}
        pos operator+(pos a){return (pos){x+a.x,y+a.y};}
        pos operator-(pos a){return (pos){x-a.x,y-a.y};}
        pos operator*(double a){return (pos){x*a,y*a};}
        double operator*(pos a){return x*a.y-y*a.x;}
        double dot(pos a){return x*a.x+y*a.y;}
        double abs(){return sqrt(x*x+y*y);}
    }ps[11];
    double mn,mx;
    struct line
    {
        pos a,b;
        void chk(line w)
         {
            double c=w.b*b;
            if(c==0)return;
            c=(a*w.b+w.b*w.a)/c;
            if(c>0.5)c<mx&&(mx=c);
            else c>mn&&(mn=c);
         }
    }ls[15],l0[11];
    int main()
    {
        scanf("%lf%lf%d",&v1,&v2,&n);
        for (int i=1;i<=n;i++)ps[i].init(),id[i]=i;
        ps[n+1]=ps[1];
        pos p1=(pos){0,0},p2=(pos){v1,0},p3=(pos){v1,v2},p4=(pos){0,v2};
        ls[lp++]=(line){p1,p2-p1};
        ls[lp++]=(line){p2,p3-p2};
        ls[lp++]=(line){p3,p4-p3};
        ls[lp++]=(line){p4,p1-p4};
        for (int i=1;i<=n;++i)l0[i]=(line){ps[i],ps[i+1]-ps[i]};
        do
         {
            lp=4;
            double s=0;
            for (int i=1;i<=n;i++)
             {
                int w=id[i];
                mn=-1e10,mx=1e10;
                for (int j=0;j<lp;j++)l0[w].chk(ls[j]);
                ls[lp++]=l0[w];
                s+=(mx-mn)*l0[w].b.abs();
             }
            if (s<ans)ans=s;
         }while(std::next_permutation(id+1,id+n+1));
        printf("%.3f",ans);
        return 0;
    }
  • 相关阅读:
    boost 无锁队列
    boost::asio 的同、异步方式
    MFC获取当前时间
    利用boost获取时间并格式化
    VS2008找不到MFC90d.dll错误解决方法
    boost库在工作(39)网络UDP异步服务端之九
    boost::asio译文
    windows 和linux 同步api对比
    BOOST::Signals2
    redhat 各种版本下载
  • 原文地址:https://www.cnblogs.com/xuanyiming/p/8458773.html
Copyright © 2011-2022 走看看