Balloons in a Box

本文介绍了一种模拟将气球放置于长方体盒子内的算法。该算法通过确定气球的最大体积并计算未被气球占据的空间体积来解决具体问题。输入包括盒子尺寸和可能放置气球的位置坐标。

Balloons in a Box


Time Limit: 3000 ms     Case Time Limit: 3000 ms     Memory Limit: 131072 KB
Submit: 6     Accepted: 1 
This problem will be judged on UVALive. Original ID: 2474.

[Prev][Next]

Description


[PDF Link]

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 

Source

World Finals, 2002 - Honolulu
#include<stdio.h>
#include<string.h>
#include<math.h>
const double pi=acos(-1.0);
int n,x1,y11,z1,x2,y2,z2,vis[10],dis[10];
double r[10],vol,max;
int abs(int a)
{
	if(a<0)
		return 0-a;
	return a;
}
struct
{
	int x,y,z;
}p[10];
int min2(int a,int b)
{
	return a<b?a:b;
}
int min3(int a,int b,int c)
{
	return min2(a,min2(b,c));
}
void solve(int k)
{
	int i,j,flag;
	if(k==n)
	{
		if(vol>max)
			max=vol;
	}
	else
		for(i=0;i<n;i++)
			if(!vis[i])
			{
				flag=0;
				r[i]=1000000001;
				for(j=0;j<n;j++)
					if(vis[j])
					{
						double d=sqrt((double)(p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y)+(p[i].z-p[j].z)*(p[i].z-p[j].z))-r[j];
						if(d<0)
						{
							flag=1;
							break;
						}
						if(r[i]>d)
							r[i]=d;
					}
				vis[i]=1;
				if(flag)
					r[i]=0;
				else
					if(r[i]>dis[i])
						r[i]=dis[i];
				vol+=4*pi*r[i]*r[i]*r[i]/3;
				solve(k+1);
				vol-=4*pi*r[i]*r[i]*r[i]/3;
				vis[i]=0;
			}
			
}
int main()
{
	int i,cnt=1;
	while(scanf("%d",&n)&&n)
	{
		scanf("%d%d%d%d%d%d",&x1,&y11,&z1,&x2,&y2,&z2);
		for(i=0;i<n;i++)
			scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].z);
		for(i=0;i<n;i++)
			dis[i]=min2(min3(abs(p[i].x-x1),abs(p[i].x-x2),abs(p[i].y-y11)),min3(abs(p[i].y-y2),abs(p[i].z-z1),abs(p[i].z-z2)));
		vol=max=0;
		memset(vis,0,sizeof(vis));
		solve(0);
		printf("Box %d: %.0f\n\n",cnt++,(double)abs(x1-x2)*abs(y11-y2)*abs(z1-z2)-max);
	}
	return 0;
}


`st.balloons()` 是 Streamlit 提供的一个**趣味性装饰函数**,用于在页面上显示动画效果的气球,通常用来表示成功操作、欢迎界面或增加交互乐趣。 --- ## ✅ `st.balloons()` 详解 ```python st.balloons() ``` ### 🔹 功能说明: - 在浏览器中触发一个**庆祝动画**:五颜六色的气球从屏幕底部飞出。 - 纯前端动画,不依赖任何数据或参数。 - 不影响程序逻辑,仅视觉反馈。 ### 🎯 常见用途: - 数据保存成功后提示 - 应用启动欢迎页 - 表单提交完成 - 模型训练结束等“正向结果”场景 --- ## ✅ 示例:结合按钮使用 ```python import streamlit as st st.title("🎉 气球演示") if st.button("点击庆祝一下!"): st.success("你触发了一个好消息!") st.balloons() # 显示气球动画 ``` > ✅ 效果:点击按钮后,页面下方会弹出持续约 3~5 秒的气球动画。 --- ## ✅ 更复杂示例:表单提交 + 气球 + 音效 ```python import streamlit as st st.title("📝 调查问卷") with st.form("my_form"): name = st.text_input("姓名") rating = st.slider("评分", 1, 5) submitted = st.form_submit_button("提交") if submitted: st.session_state.submitted = True st.success(f"谢谢 {name} 的评分!⭐{rating}") st.balloons() # 庆祝提交成功 # 可选:播放音效(HTML5 Audio) st.markdown(""" <audio autoplay> <source src="https://www.soundjay.com/misc/sounds/bell-ringing-05.mp3" type="audio/mpeg"> </audio> """, unsafe_allow_html=True) ``` > 💡 提示:Streamlit 不原生支持音效,但可通过 HTML `<audio autoplay>` 实现。 --- ## ⚠️ 注意事项 | 问题 | 说明 | |------|------| | `st.balloons()` 是否可关闭? | 动画自动播放完即消失,无法手动关闭 | | 是否可在非交互场景调用? | 可以,但建议只在用户触发事件后调用(如按钮点击) | | 是否支持自定义颜色/样式? | ❌ 不支持。这是硬编码的固定动画 | | 多次调用会不会卡顿? | 会叠加动画,可能影响性能,建议限制频率 | | 手机端是否可用? | ✅ 支持,但在低端设备上可能帧率较低 | --- ## 🧩 相关函数(Streamlit 内置动画) | 函数 | 作用 | |------|------| | `st.balloons()` | 气球飞舞庆祝 | | `st.snow()` | 下雪动画(冬季主题) | | `st.toast(msg)` | 显示轻量级通知(类似 snackbar) | | `st.spinner()` | 显示加载中旋转图标 | ### 示例对比: ```python import time if st.button("庆祝 + 下雪"): with st.spinner("准备中..."): time.sleep(1) st.success("完成啦!") st.toast("已保存", icon="✅") st.balloons() st.snow() ``` --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值