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 requirements of the alloy

First of all, the idea of this problem is particularly fascinating to see how this problem can be thought of computational geometry and computational geometry and how to hang with Floyd.

First of all because of a+b+c=1 so we just got a and B 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

So we select some of the raw materials, the alloys that can be synthesized by these materials must be shown on the convex hull of these points.

So we turn the problem into this: given two point sets A and B, the smallest subset of s in a, so that all the points in B are 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 point 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 on the IJ of the segment (The red dots in the figure) without dots in the green point of the figure, a i->j one-way edge is connected

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

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 rob 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.