HDU 3362 Fix (pressure dp)

Source: Internet
Author: User

Fix

Time limit:20000/10000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 1037 Accepted Submission (s): 349

problem DescriptionThere is a few points on a plane, and some is fixed on the plane, some is not. We want to connect these points by some sticks so, all the points is fixed on the plane. Of course, we want to know the minimum length of the sum of the sticks.

As in the images, the black points is fixed on the plane and red ones is not, which need to is fixed by sticks.
All the points with the left image has been fixed. But the middle one isn't, which we need add one stick to fix those four points (the right image shows that stick). Triangle is steady, isn ' t it?\ InputThe input consists of multiply test cases. The first line of all test case contains one integer, n (1 <= n <=), which is the number of points. The next n lines, each line consists of three integers, x, y, C (0 <= x, y < 100). (x, Y) indicate the coordinate of one point; c = 1 indicates this is fixed; c = 0 Indicates this is not fixed. You can assume that no points has the same coordinate.
The last test case was followed by a line containing one zero, which means the end of the input. OutputOutput the minimum length with six factional digits for each test case in a single line. If You cannot fix all the points and then output "No solution". Sample Input40 0 11 0 10 1 01 1 030 0 11 1 02 2 00 Sample Output4.414214No Solution Source"Guang Ting Cup" The fifth session of the North Central District programming Competition and WHU eighth session of the Program design contest

The main idea is to fix the minimum number of sticks needed for the moving point.

+DP: State compression

#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>using namespacestd;Doubleinf=100000000000.0;Doubledis[300000];intN;intStart,target;structnode{Doublex, y; BOOLfix;} p[ -];DoubleCalintAintb) {  returnsqrt ((Double) ((p[a].x-p[b].x) * (p[a].x-p[b].x) + (P[A].Y-P[B].Y) * (p[a].y-P[B].Y))) ;}DoubleWorkintKintt) {    Doubledis[ -]; intL=0;  for(intI=0; i<n;i++)     if(k& (1<<i)) dis[l++]=cal (i,t);//Determine if the first point is fixedif(l<2)return-1; Sort (Dis,dis+L);//first Parameter first address of sort, second argument end address, sort range "[,)"    returndis[0]+dis[1];}intMain () { while(~SCANF ("%d",&N)) {if(n==0) Break; Start=0; Target=0;  for(intI=0; i<n;i++) {scanf ("%lf%lf%d",&p[i].x,&p[i].y,&P[i].fix); Start=start| (p[i].fix<<i); Target=target| (1<<i); }        for(intI=0; i<=target;i++) dis[i]=inf; Dis[start]=0;  for(intk=start;k<=target;k++)       {
if (Dis[k]==inf) continue; This sentence is best added for(intI=0; i<n;i++) if( ! (k& (1<<i))//Determine if the point I can move, if you can continue to do {Doubleres=Work (k,i); if(res>0) dis[k| (1<<i)]=min (dis[k| (1<<i)],dis[k]+res); } } if(Dis[target]==inf) printf ("No solution\n"); Elseprintf"%.6lf\n", Dis[target]); } return 0;}

HDU 3362 Fix (pressure dp)

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.