P1378 extension for oil drops and p1378 extension for oil drops

Source: Internet
Author: User

P1378 extension for oil drops and p1378 extension for oil drops
Description

In a rectangle frame, there can be at most N (0 ≤ N ≤ 6) different points. Put a small oil drop on any of them, the oil drops will continue to expand, until it is exposed to the boundaries of other oil drops or frames. You must wait for the extension of one oil drop before placing the next oil drop. In what order should the oil drops be placed on the N points to maximize the total volume occupied by all the oil drops after the placement? (Different oil drops do not integrate with each other)

Note: The area formula of the circle V = pi * r, where r is the radius of the circle.

Input/Output Format Input Format:

The value is an integer N in the first row.

2nd act the coordinates of a vertex in the rectangular border and its diagonal vertex, x, y, x', y '.

Next N rows. Each line has two integers xi and yi, which indicate the coordinates of the N points of the box.

All the above data is in.

Output Format:

A row, an integer, and the minimum space remaining in the Rectangular Box (the result is rounded to the output)

Input and Output sample Input example #1:
220 0 10 1013 317 7
Output sample #1:
50

First, DFS generates a complete arrangement.
Then, make a judgment and obtain the minimum value of the value that can be obtained.
Note that when a stretch distance is negative, it must be changed to 0.

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <algorithm> 6 using namespace std; 7 double dis [7] [7]; 8 int map [2001] [2001]; 9 struct node 10 {11 int bh; // number 12 int wx, wy; // position 13 double kzjl; // extended distance 14} a [2001]; 15 int x11, y11, x22, y22, n, ans = 0x7ffffff, minx, miny, maxx, maxy; 16 int how [7]; 17 int vis [7]; 18 int fact [10] = {24,120,720,}; 19 void deal_dis () 20 {21 for (int I = 1; I <= n; I ++) 22 for (int j = 1; j <= n; j ++) 23 dis [I] [j] = sqrt (a [I]. wx-a [j]. wx) * (a [I]. wx-a [j]. wx) + (a [I]. wy-a [j]. wy) * (a [I]. wy-a [j]. wy); 24} 25 26 void pd () 27 {28 for (int I = 1; I <= n; I ++) 29 a [I]. kzjl = 0; 30 for (int I = 1; I <= n; I ++) 31 {32 a [how [I]. kzjl = min (abs (maxy-a [how [I]. wy), abs (a [how [I]. wy-miny), min (abs (maxx-a [how [I]. wx), abs (a [how [I]. wx-minx); 33 for (int j = 1; j <I; j ++) 34 a [how [I]. kzjl = min (dis [how [I] [how [j]-a [how [j]. kzjl), a [how [I]. kzjl); 35 if (a [how [I]. kzjl <0) 36 a [how [I]. kzjl = 0; 37} 38 double now = 0; 39 for (int I = 1; I <= n; I ++) 40 {41 now + = a [I]. kzjl * a [I]. kzjl * acos (-1); 42} 43 now = (abs (maxx-minx) * (abs (maxy-miny)-now; 44 now = (int) (now + 0.5); 45 ans = min (ans, (int) now); 46} 47 48 void dfs (int p, int num) // num: The I drop, p: 49 {50 how [num] = p; 51 if (num = n) 52 {53 pd (); 54 return; 55} 56 for (int I = 1; I <= n; I ++) 57 {58 if (vis [I] = 0) 59 {60 vis [I] = 1; 61 dfs (I, num + 1); 62 vis [I] = 0; 63} 64} 65 66} 67 68 int main () 69 {70 // freopen ("oilbox. in "," r ", stdin); 71 // freopen (" oilbox. out "," w ", stdout); 72 73 74 scanf (" % d ", & n, & x11, & y11, & x22, & y22); 75 minx = min (x11, x22); miny = min (y11, y22); maxx = max (x11, x22); maxy = max (y11, y22); 76 77 if (n = 0) 78 {79 printf ("% d", (maxx-minx) * (maxy-miny); 80 return 0; 81} 82 83 for (int I = 1; I <= n; I ++) 84 {85 scanf ("% d", & a [I]. wx, & a [I]. wy); 86 how [I] = I; 87 a [I]. bh = I; 88 a [I]. kzjl = 0; 89} 90 91 deal_dis (); 92 93 for (int I = 1; I <= fact [n]; I ++) 94 {95 vis [I] = 1; 96 dfs (I, 1); 97 vis [I] = 0; 98} 99 100 printf ("% d", ans ); 101 return 0; 102}

 

 

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.