****The Toy of Flandre Scarlet

The Toy of Flandre Scarlet

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Submit Status

Description

As you know, Flandre Scarlet loves her elder sister Remilia Scarlet, and of course, Remilia loves Flandre, too. But because ofFlandre's unstable personality and incredible destructive power, Remilia has asked Flandre not to leave Scarlet Devil Mansion for nearly 500 years. The life of Flandre is so boring that it's no surprising that she did some unimaginable things. To solve this problem,Remilia decides to give a interesting big cubic toy to Flandre and tell her how to play so that Flandre can have fun.

****The Toy of Flandre Scarlet

The interesting toy's length is L meters, while its width is W meters and height is H meters. And, the toy can be split into L * W * Hstandard cube. The length, width and height of the standard cubes are all 1 meter.

Remilia prints a number on each standard cube. What's more, Flandre can add or subtract a same integer on two adjacent standard cube for arbitary times. Two cubes are adjacent if they share the same surface.

The goal of this game is making all the number become 0. Can you help Flandre to solve the problem to get some candies from her sisterRemilia?

Input

There are multiple test cases.

Each test case consists of two parts.

The first part contains a single line with three integers: LWH (1 ≤ L, W, H ≤ 4).

The second part consists of L sections. Each section consists of W lines, each line consists of H integers. In lth section, the hth integer of the wth line denotes the number in the given cube. All numbers are in range [0, 100].

There is a blank line between every two cases.

Output

One line for each case. If Flandre can success, you should print "Yes" (ignore quotes), otherwise you should print "No" (ignore quotes).

Sample Input

1 1 1
1 2 2 2
1 1
1 1
1 1
1 1

Sample Output

No
Yes

题目大意:是有L*W*H个1*1*1的小方块,堆成长L,宽W,高H的玩具。每个小方块上有一个数字,每次我们可以让某相邻的两个小方块,同时加上或减去一个相同的数字。问经过若干步后能不能使所有数字均为0。

显然可以转化成图来考虑。假设A, B, C, D依次相邻,分别对应1,2,3,4。经过三次操作,AB-1,BC+1, CD-1,可使D=D-A,A=0;通过两次操作,BC-2,CD+2,可使D=D+B,B=0;然后显然一次可使D=D-C,C=0。不难将这个规律推广到一般的情况,又原图必为连通图,可选一原点,例如(0,0,0),让其他所有点的数值通过以上步骤变为0,而加成或约减到(0,0,0)这个点上来。若最终该点值为零,则可达到目标。注意到在三维坐标系中,任意两整点间的距离要么是奇数要么是偶数,这一点可以反映在三个坐标值上。因此有下面的代码。用C写纯粹是为了Rank,不过有人已经这样干过于是只能排第二了。

代码:

 #include <stdio.h>

 int l, w, h;
int sum[]; int main()
{
int t, i, j, k;
while(scanf("%d%d%d", &l, &w, &h) != EOF)
{
sum[] = sum[] = ;
for(i=; i<l; ++i)
{
for(j=; j<w; ++j)
{
for(k=; k<h; ++k)
{
scanf("%d", &t);
sum[(i+j+k)%] += t;//根据该点距离原点的距离进行奇偶分类。
}
}
}
if(sum[] == sum[])
printf("Yes\n");
else
printf("No\n");
}
return ;
}
上一篇:【MyBatis】MyBatis 动态 SQL


下一篇:CentOS裸机环境下安装php-7.3.1