Bzoj 1027 JSOI2007 alloy calculation geometry +floyd

Source: Internet
Author: User

The main topic: given some alloys, choose the least alloy, so that these alloys can be synthesized according to the required alloy

First of all, the idea of this problem is very strange to see how this problem can be thought of computational geometry and calculate geometry and how to hang with Floyd good strong

First because a+b+c=1 so we just have to get a and B can c=1-a-b so C can not read into the

And then we abstracted each ingredient into a single point, and we know that the two-point alloy must be on a two-point line.

Proof: Set two points for (x1,y1) and (X2,y2), the newly synthesized alloy for (ax1+bx2,ay2+by2) (a+b=1,a,b>0) two point line for (y-y1)/(X-X1) = (y-y2)/(X-X2), substituting can be proven

Then we select some raw materials. These materials can be synthesized by the alloy must be at these points on the convex hull to prove a little

So we turn the problem into this: given two point sets a and B, find the smallest subset of s in a. Make all the points in B inside the convex hull of s

How do we deal with this problem? Here's a very ingenious way to do it.


, enumerate a point set two points i,j (I can be equal to J) if all points in the B-point set are on the left side of the vector i->j or in the segment IJ (the red dots in the figure) and no dots are located in the green point of the figure. One-way side of a i->j is connected.

Even if random B-point concentration point K satisfies (k->i) x (k->j) <0| | (k->i) x (k->j) ==0&& (k->i) · (K->J) <=0 is connected to a i->j one-way side

And then Floyd to find the smallest ring.

Correctness of their own yy it should be able to reduce a lot of discussion and will not be stuck out of the way the data is too weak ...

#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define M 510#define INF 0x3f3f3f3f#define EPS 1e-7using namespace std;struct point{double x,y;point Operato R-(const point z) {point re;re.x=x-z.x;re.y=y-z.y;return Re;} Double operator * (const point z) {return x*z.y-y*z.x;} Double operator ^ (const point z)//Hello everyone I am the dot product multiplication sign was cross product robbed the owner can only give me this ~ {return x*z.x+y*z.y;}} A[m],b[m];int m,n;int map[m][m],f[m][m];int ans=inf;void Floyd () {int i,j,k;memcpy (f,map,sizeof f); for (k=1;k<=m;k+ +) for (i=1;i<=m;i++) if (F[i][k]<inf) for (j=1;j<=m;j++) f[i][j]=min (F[i][j],f[i][k]+f[k][j]); for (i=1;i< =m;i++) Ans=min (Ans,f[i][i]);} int main () {int i,j,k;memset (map,0x3f,sizeof map), cin>>m>>n;for (i=1;i<=m;i++) scanf ("%lf%lf%*lf", &AMP;A[I].X,&AMP;A[I].Y); for (i=1;i<=n;i++) scanf ("%lf%lf%*lf", &b[i].x,&b[i].y); for (i=1;i<=m;i++) for (j=1;j<=m;j++) {for (k=1;k<=n;k++) {double cross= (a[i]-b[k]) * (A[j]-b[k]), if (cross>eps) BREak;if (Fabs (cross) <eps && (A[i]-b[k]^a[j]-b[k]) >eps) break; if (k==n+1) map[i][j]=1;} Floyd (); if (Ans==inf) Ans=-1;cout<<ans<<endl;}


Bzoj 1027 JSOI2007 alloy calculation geometry +floyd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.