The Toy of Flandre Scarlet
Time Limit: 2 Seconds Memory Limit: 65536 KB
As you know, Flandre Scarlet loves her elder sister Remilia Scarlet, and of course, Remilia loves Flandre, too. But because of Flandre‘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 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 * H standard 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 sister Remilia?
There are multiple test cases.
Each test case consists of two parts.
The first part contains a single line with three integers: L, W, H (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.
One line for each case. If Flandre can success, you should print "Yes" (ignore quotes), otherwise you should print "No" (ignore quotes).
題目大意:題目意思是給你一個cube,他的長寬高,l,w,h,然後總共有l*w*h個格子,每個格子上面上有一個數字,然後可以每次可以操作,使得兩個相鄰的格子裡的數字同時加上一個數字或者同時減去一個數字。問你操作次數不限定,能否使得cube數字全為0。
記得高中那會兒玩兒魔方的時候,下課了一個老師問過我這個問題,魔方的每個格子有數,相鄰的可加加減減,歸零的條件隻需要八個頂角加上六個面心的和等于十二個棱角加上核的和即可。
其實可以簡單的畫一個二維的3*3的
1 0 1
0 1 0
其實我們不管怎麼對這個圖處理,四個角加上中心點的和減去四條邊上的和的值始終等于5。
因為我們可以對每個點分類,每次都是這兩類的同加同減,他們的差不變,自己體會。。
題目位址:
AC代碼: