UVALive 2474Balloons in a Box(枚举)
Posted surprisezang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVALive 2474Balloons in a Box(枚举)相关的知识,希望对你有一定的参考价值。
https://vjudge.net/contest/277824#problem/A
尤其是模拟题,三思而后敲!!!
纠错了好久,主要还是没有处理好:单点若还未放气球,其他气球可以膨胀越过它(即可以无视这个点);如果选到一个点,它已经在某一气球半径内了,则置r=0.
还参考了一些其他测试数据
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<vector> 5 #include<cstring> 6 #include<queue> 7 #include<cmath> 8 const double PI = acos(-1.0);//记住PI 9 using namespace std; 10 int n, vis[10]; 11 double maxm; 12 double x1, x2, yy1, y2, z1, z2; 13 double a[10], b[10], c[10], r[10]; 14 double dist(double a, double b, double c){ 15 return sqrt(a*a+b*b+c*c); 16 } 17 double cal_min(double a, double b, double c){ 18 double tmp1 = min(fabs(a-x1), min(fabs(b-yy1), fabs(c-z1))); 19 double tmp2 = min(fabs(a-x2), min(fabs(b-y2), fabs(c-z2))); 20 return min(tmp1, tmp2); 21 } 22 void dfs(double sum, int k) 23 { 24 if(k == n){ 25 maxm = max(sum, maxm); 26 } 27 else 28 for(int i = 0; i < n; i++){ 29 if(!vis[i]){//主要问题处在下面的处理 30 r[i] = cal_min(a[i], b[i], c[i]); 31 for(int j = 0; j < n; j++){//这里不能加j!=i 32 if(vis[j] == 1){ 33 if(dist(a[i]-a[j], b[i]-b[j], c[i]-c[j])>r[j]) 34 r[i] = min(dist(a[i]-a[j], b[i]-b[j], c[i]-c[j])-r[j], r[i]); 35 else r[i] = 0; 36 } 37 } 38 sum += r[i]*r[i]*r[i]; 39 vis[i] = 1; 40 dfs(sum, k+1); 41 sum -= r[i]*r[i]*r[i]; 42 vis[i] = 0; 43 } 44 } 45 } 46 int main() 47 { 48 int kase=0; 49 while(~scanf("%d", &n)&&n){ 50 51 scanf("%lf%lf%lf", &x1, &yy1, &z1); 52 scanf("%lf%lf%lf", &x2, &y2, &z2); 53 for(int i = 0; i < n; i++){ 54 scanf("%lf%lf%lf", &a[i], &b[i], &c[i]); 55 } 56 memset(vis, 0, sizeof(vis)); 57 memset(r, 0, sizeof(r)); 58 maxm = 0; 59 dfs(0, 0); 60 printf("Box %d: %.0lf ", ++kase, (fabs(x2-x1)*fabs(y2-yy1)*fabs(z2-z1)-maxm*PI*4.0/3.0));//a*b*c-(4/3)*PI*r*r*r 61 } 62 return 0; 63 }
以上是关于UVALive 2474Balloons in a Box(枚举)的主要内容,如果未能解决你的问题,请参考以下文章
算法训练 Balloons in a Box (枚举,模拟)
[2016-03-19][UVALive][3644][X-Plosives]