Description
Input
有若干行,每行三个数字 X;Y;Z 代表一组数据,表示立方体的长宽高加 1
Output
第 i 行数据输出Case#i: 第i组数据的答案
Sample Input
2 1 2
2 2 2
Sample Output
Case #1: 4
Case #2: 15
HINT
x,y,z<=1000
Source
最早的时候我以为这题是个姿势非常高的数据结构或者图论题,后来发现可以对不同边长的立方体进行分类讨论…
显然有一些边的数目是必须走的,然后我们讨论那些要重复走的
讨论的基本思想是考虑先讨论低维情况,逐步扩展到高维.
讨论的细节可以看莱芜一中的大爷DQS的题解
看完大爷的题解我才知道原来是考虑对原图构造一个奇数度数点有两个的欧拉回路然后讨论答案的..比我这种直接考虑几何图形然后讨论答案的姿势厉害到不知道哪里去啦!(不过讨论的结果好像是一样的?没有仔细看
此题烧脑,拒绝进行答疑了QAQ(脑子本来就小,再烧就没有啦
DQS的题解
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define GET (ch>='0'&&ch<='9')
using namespace std;
int T,x,y,z;
inline bool in(int &x)
{
char ch=getchar();x=0;
while (!GET) { if (ch==EOF) return 0;ch=getchar(); }
while (GET) x=x*10+ch-'0',ch=getchar();return 1;
}
inline long long get(int x,int y,int z)
{
long long sum=1ll*z*((x-1)*y+x*(y-1))+1ll*x*y*(z-1);
if (x==1) return (y==1||(y==2&&z==2))?sum:((y&1)&&(z&1)?sum+y+z-4:sum+y+z-5);
if (x==2) return sum+(y-2)*(z-2)+3;
if (x==3) return (y&1)&&(z&1)?sum+(y-2)*(z-2)+(x-2)*(y-2)+(x-2)*(z-2)+9:(((y&1)||(z&1))?sum+(y-2)*(z-2)+(x-2)*(y-2)+(x-2)*(z-2)+7:sum+(y-2)*(z-2)+(x-2)*(y-2)+(x-2)*(z-2)+6);
return sum+(y-2)*(z-2)+(x-2)*(y-2)+(x-2)*(z-2)+9;
}
int main()
{
while (in(x)&&in(y)&&in(z))
{
if (x>y) swap(x,y);
if (x>z) swap(x,z);
if (y>z) swap(z,y);
printf("Case #%d: %lld\n",++T,get(x,y,z));
}
}