转载了枚举总结,又回顾了USACO1.2章,感觉自己还是要多看点东西。
盒子里的气球
Accept: 265 Submit: 1430
Time Limit: 1000 mSec Memory Limit : 32768 KB
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 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
Sample Output
Source
FZU 2007 ICPC Qualification Round I#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double x[15],y[15],z[15],r[15];
double X1,Y1,Z1,X2,Y2,Z2,maxV;
int n,sel[15];
bool vis[15];
const double pi=acos(-1.0);
double getside(int i)
{
double dis1,dis2,dis3;
dis1=min(fabs(x[i]-X1),fabs(x[i]-X2));
dis2=min(fabs(y[i]-Y1),fabs(y[i]-Y2));
dis3=min(fabs(z[i]-Z1),fabs(z[i]-Z2));
return min(dis1,min(dis2,dis3));
}
double distances(int a,int b)
{
return sqrt((x[a]-x[b])*(x[a]-x[b])+
(y[a]-y[b])*(y[a]-y[b])+
(z[a]-z[b])*(z[a]-z[b]));
}
void getV()
{
double a,v=0;
for(int i=0;i<n;i++)
{
a=getside(sel[i]);
for(int j=0;j<i;j++)
a=min(a,distances(sel[i],sel[j])-r[sel[j]]);
r[sel[i]]=(a<0)?0:a;
if(a<=0) continue;
v+=(4.0/3*pi*r[sel[i]]*r[sel[i]]*r[sel[i]]);
}
maxV=max(maxV,v);
}
void dfs(int cnt)
{
if(cnt==n)
getV();
else
{
for(int i=0;i<n;i++)
{
if(vis[i]) continue;
sel[cnt]=i;
vis[i]=1;
dfs(cnt+1);
vis[i]=0;
}
}
}
int main()
{
int te=1;
while(~scanf("%d",&n)&&n)
{
scanf("%lf%lf%lf",&X1,&Y1,&Z1);
scanf("%lf%lf%lf",&X2,&Y2,&Z2);
for(int i=0;i<n;i++)
scanf("%lf%lf%lf",&x[i],&y[i],&z[i]);
maxV=0;
memset(vis,0,sizeof(vis));
dfs(0);
printf("Box %d: %.0lf\n\n",te++,((fabs((X1-X2)*(Y1-Y2)*(Z1-Z2)))-maxV));
}
return 0;
}
USACO 1.2--Palindromic Squares
#include <stdio.h>
int B;
int x[20],l,y[20],L;
void Change(int n)
{
int m;
m=n, l=0; while(m) x[++l]=m%B, m/=B;
m=n*n, L=0; while(m) y[++L]=m%B, m/=B;
}
int pd()
{
int i,j;
for(i=1,j=L;i<=j;++i,--j)
if(y[i]!=y[j]) return 0;
return 1;
}
int main()
{
freopen("palsquare.in","r",stdin);
freopen("palsquare.out","w",stdout);
int i,j;
char c[20]={ '0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F','G','H','I','J' };
scanf("%d",&B);
for(i=1;i<=300;++i)
{
Change(i);
if(pd())
{
for(j=l;j>=1;--j) printf("%c",c[x[j]]); printf(" ");
for(j=L;j>=1;--j) printf("%c",c[y[j]]); printf("\n");
}
}
return 0;
}
USACO 1.2--namenum
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char a[26] = {'2','2','2','3','3','3','4','4','4','5','5','5', '6','6','6','7','0','7','7','8','8','8','9','9','9','0'};
char s[13];
char name[13];
int main()
{
freopen ("namenum.in", "r",stdin);
freopen ("namenum.out", "w",stdout);
int i;
int flag = 1;
int len;
scanf ("%s", &s);
len = strlen(s);
freopen ("dict.txt", "r",stdin);
while(scanf("%s", name) != EOF)
{
if(strlen(name) == len)
{
int flg = 1;
for(i = 0; i < len && flg; i++)
{
if(a[name[i]-'A'] != s[i])
{
flg = 0;
}
}
if(flg)
{
printf ("%s\n", name);
flag = 0;
}
}
}
if(flag)
{
printf ( "NONE\n");
}
return 0;
}