bzoj1027: [JSOI2007]合金

來源:互聯網
上載者:User

標籤:start   space   geo   座標系   src   ret   color   ++i   print   

http://www.lydsy.com/JudgeOnline/problem.php?id=1027

完全不會寫然後聽隔壁未來IOI爺講的 Orzccz

因為第三維可以由前兩維推出所以就變成了一些點

然後題目就可以轉化為求一個最小的凸多邊形使得所有點都在這個凸多邊形內

然後就可以floyd

對於原材料合金中的兩個,為座標系中的兩點,若所有需要的合金都在其一側(不妨統一設為左側),則連一條長度為1的有向邊。

 1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #define rep(i,l,r) for(int i=l;i<=r;++i) 7 using namespace std; 8 const int N=520; 9 typedef double d;10 int n,m,ans,f[N][N],flag;11 d c;12 struct point{13     d x,y;14 }a[N],b[N];15 typedef point vector;16 const d eps=1e-7;17 vector operator - (point a,point b){18     return (vector){a.x-b.x,a.y-b.y};19 }20 d cross(vector a,vector b){21     return a.x*b.y-a.y*b.x;22 }23 d cross(point a,point b,point c){  24     return cross(b-a,c-a);25 }26 d dot(vector a,vector b){27     return a.x*b.x+a.y*b.y;28 }29 d dot(point a,point b,point c){30     return dot(b-a,c-a);31 }32 int main(){33     scanf("%d%d",&n,&m);34     rep(i,1,n)scanf("%lf%lf%lf",&a[i].x,&a[i].y,&c);35     rep(i,1,m)scanf("%lf%lf%lf",&b[i].x,&b[i].y,&c);36     memset(f,60,sizeof f);37     rep(i,1,n) rep(j,1,n) {38         flag=1;39         rep(k,1,m){40             c=cross(b[k],a[i],a[j]);41             if(c>eps||(fabs(c)<eps&&dot(b[k],a[i],a[j])>eps)){42                 flag=0;43                 break; 44             }45         }46         if(flag) f[i][j]=1;47     }48     rep(k,1,n) rep(i,1,n) rep(j,1,n) f[i][j]=min(f[i][j],f[i][k]+f[k][j]);49     ans=1e9;50     rep(i,1,n) ans=min(ans,f[i][i]);51     printf("%d\n",ans>=1e9?-1:ans);52 }
View Code

 

bzoj1027: [JSOI2007]合金

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.