• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

LA 2427 Balloons in a Box

Balloons in a Box

WA了一版真的找不到错误!

妈蛋,找到了,(a.y - b.y)*(a.y - b.y)+(a.z - b.z)*(a.z - b.z)中间一直用的是*号,妈蛋,这样为什么样例能对,fu*k!

You must write a program that simulates placing spherical balloons into a rectangular box.

The simulation scenario is as follows. Imagine that you are given a rectangular box and a set of points. Each point represents a position where you might place a balloon. To place a balloon at a point, center it at the point and inflate the balloon until it touches a side of the box or a previously placed balloon. You may not use a point that is outside the box or inside a previously placed balloon. However, you may  use the points in any order you like, and you need not use every point. Your objective is to place balloons in the box in an order that maximizes the total volume occupied by the balloons.

You are required to calculate the volume within the box that is not enclosed by the balloons.

Input 

The input consists of several test cases. The first line of each test case contains a single integer n that indicates the number of points in the set (1 <= n<= 6). The second line contains three integers that represent the (x, y, z) integer coordinates of a corner of the box, and the third line contains the (x, y, z) integer coordinates of the opposite corner of the box. The next n lines of the test case contain three integers each, representing the (x, y, z) coordinates of the points in the set. The box has non-zero length in each dimension and its sides are parallel to the coordinate axes.

The input is terminated by the number zero on a line by itself.

Output 

For each test case print one line of output consisting of the test case number followed by the volume of the box not occupied by balloons. Round the volume to the nearest integer. Follow the format in the sample output given below.

Place a blank line after the output of each test case.

Sample Input 

2 
0 0 0 
10 10 10 
3 3 3 
7 7 7 
0 

Sample Output 

Box 1: 774
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 105
14 const double pi = acos(-1.0);
15 struct point {double x, y, z;}b[maxn];
16 //const int maxk = 10 + 1, inf = ~0U >> 2;
17 double a[maxn], d[maxn];
18 int vis[maxn];
19 int n, m;
20 double ans;
21 double fun(point a, point b,int u){return max(0.0,sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y)+(a.z - b.z)*(a.z - b.z)) - d[u]);}
22 double vf(double r){return pi*r*r*r / 3.0 * 4.0;}
23 void dfs(int u,int k){
24     double s = 10000000;
25     s = min(s, fabs(b[u].x - a[0]));
26     s = min(s, fabs(b[u].x - a[3]));
27     s = min(s, fabs(b[u].y - a[1]));
28     s = min(s, fabs(b[u].y - a[4]));
29     s = min(s, fabs(b[u].z - a[2]));
30     s = min(s, fabs(b[u].z - a[5]));
31     for (int i = 0; i < n; i++)
32     if (i!=u&&vis[i])
33         s = min(s,fun(b[u], b[i],i));
34     if(k)d[u] = s;
35     if (k == n){ans = max(ans, vf(d[0]) + vf(d[1]) + vf(d[2]) + vf(d[3]) + vf(d[4]) + vf(d[5])); return;}
36     for (int i = 0; i < n; i++){
37         if (vis[i])continue;
38         vis[i] = 1;
39         dfs(i,k+1);
40         vis[i] = 0;
41         d[i] = 0.0;
42     }
43 }
44 int main(){
45     int cas = 1;
46     while (scanf("%d", &n) && n){
47         scanf("%lf%lf%lf", &a[0], &a[1], &a[2]);
48         scanf("%lf%lf%lf", &a[3], &a[4], &a[5]);
49         for (int i = 0; i < n; i++)
50             scanf("%lf%lf%lf", &b[i].x, &b[i].y, &b[i].z);
51         ans = 0.0;
52         dfs(0,0);
53         printf("Box %d: ", cas++);
54         printf("%.0lf\n\n", (fabs((a[3]-a[0])*(a[4]-a[1])*(a[5]-a[2]))-ans));
55     }
56     return 0;
57 }
View Code

 

posted @ 2013-12-26 03:43  HaibaraAi  阅读(165)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3