FixTime
limit:20000/10000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 916 Accepted Submission (s): 309
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 Input
40 0 11 0 10 1 01 1 030 0 11 1 02 2 00
Sample Output
4.414214No Solution
Source "Guang Ting Cup" The fifth session of the Central China North District Programming Invitational and WHU eighth session of the Program design contest
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath > #include <vector> #include <queue> #include <set> #include <algorithm> #define LL Long longusing namespace Std;const int maxn = 20;const double INF = 100000000.0;struct node{int x, y;} Point[maxn];int FIX[MAXN], start, target, n;double DIS[MAXN], dp[1<<21];d ouble dis (int a, int b) {Double x = (dou ble) (point[a].x-point[b].x); Double y = (double) (POINT[A].Y-POINT[B].Y); return sqrt (x * x + y * y);} Double solve (int s, int x) {int m = 0; for (int i=0;i<n;i++) if (S & (1 << i)) dis[m++] = Dis (i, x); Sort (dis, dis + m); cout << m << Endl; if (M < 2) return-1; Double ans = dis[0] + dis[1]; return ans;} int main () {while (scanf ("%d", &n)!=eof && N) {start = target = 0; for (int i=0;i<n;i++) {scanf ("%d%d%d", &point[i].x, &poINT[I].Y, &fix[i]); if (Fix[i]) Start |= (1 << i); Target |= (1 << i); } for (int i=0;i<=target;i++) dp[i] = INF; Dp[start] = 0; for (int s=start;s<=target;s++) {if (dp[s] = = INF) continue; for (int i=0;i<n;i++) {if (!) ( S & (1 << i)) {Double res = solve (s, i); cout << s << ' << i << ' << res << Endl; if (res >= 0) dp[s| ( 1<<i)] = min (dp[s| ( 1<<i)], Dp[s] + res); cout << Dp[s] << ' << dp[s| ( 1<<i)] << Endl; }}} if (Dp[target] >= INF) printf ("No solution\n"); else printf ("%.6lf\n", Dp[target]); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 3362 Fix (pressure dp)