算法设计与分析 盒子里的气球程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

前/下 三个面的距离。 mi[3]=abs(p[i].x-b[1].x);mi[4]=abs(p[i].yb[1].y);mi[5]=abs(p[i].z-b[1].z); //求出 i点距盒子右/ 后/上 三个面的距离。 for(j=0;j<6;j++ ) if(mi[j]<m) m=mi[j]; //m记录i点与长方体六个面的最小距 离值 for(j=0;j<n;j++) { if(i!=j vis[j]==true) { m=min(m,volume(p[i],p[j])p[j].r); } } //求出i点与其余的点的距离,再与m比较,返回的m便 是i点的最大可能半径 // printf("%.2lf\n",m); return m; } &&
are parallel to the coordinate axes. Output For each test case print one line which indicates the volume of the box not occupied by balloons. Round the volume to the nearest integer. Sample Input 2 000 10 10 10 333 777 Sample Output 774 #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> int n; double v,sv; struct po
大允许的半径 if(p[i].r>0) dfs(step+1,bv+ (4.0/3.0)*pi*p[i].r*p[i].r*p[i].r); else dfs(step+1,bv); Vis[i]=false; }
}
}
int main() { int i,j; while(scanf("%d",&n)!=EOF) //输入点数 {
void dfs(int step,double bv)//bv代表气 球的体积和 { if(step==n) { if(bv>v) v=bv; return ; } else { for(int i=0;i<n;i++) if(!vis[i]) { Vis[i]=true; //置第i点为可已访 问,即已遍历 p[i].r=minst(i); //求出i点的最
盒子战斗力算法lol盒子战斗力算法算法设计与分析算法分析的目的是数学建模算法与程序数据结构与算法分析算法分析算法与程序设计算法与程序框图算法设计技巧与分析
盒子里的气球 算法
盒子里的气球 枚举法 刘汝佳 算法艺术与信息学竞 赛
Problem Description 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 inside the box. 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 use the points in any order you like, and 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. All integer will be in [-1000, 1000]. 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 (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
scanf("%d%d%d%d%d%d",&b[0].x,&b[0].y,&b[0].z,&b[1].x,&b[1].y,&b //输入长方体盒子的左下低角坐标和右上顶角坐标
sv=fabs(b[0].x-b[1].x)*abs(b[0].y-b[1].y)*abs(b[0].z-b[1].z);// 方体 scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].z); p[i].r=0; } //输入盒内点的坐标,并置每点上 气球半径=0 v=0; memset(vis,0,sizeof(vis));//用于标记 是否遍历过 dfs(0,0.0); printf("%.lf\n",svv); } return 0; }
{ int x, y, z; double r; }p[10],b[2];
bool vis[10];
const double pi =3.141592653 const double inf=10000000000.0;
double min(double a,double b) { if(a<b) return a;
else return b; }
double volume(po a,po b)//两点之 间的距离 { return sqrt((double)(a.x-b.x)*(a.x-b.x)+(a.y-b.y)* (a.y-b.y)+(a.z-b.z)*(a.z-b.z)); }
double minst(int i)//找点i上的气球的 最大半经 { int j; double m=inf; double mi[6]; mi[0]=abs(p[i].x-b[0].x);mi[1]=abs(p[i].yb[0].y);mi[2]=abs(p[i].z-b[0].z); //求出 i点距盒子左/
相关文档
最新文档