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 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 ;
}

****The Toy of Flandre Scarlet的更多相关文章

  1. BZOJ2553: [BeiJing2011]禁忌

    2553: [BeiJing2011]禁忌 Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 203  Solved: ...

  2. BNU10806:请在此处签到

    每年圣诞,ZUN都会邀请很多人到幻想乡举行联欢,今年也不例外.在联欢前,所有人需要在自己的昵称旁签到(签全名),以示出席.然后ZUN 会把大家的签到表保存下来作为纪念,以激励来年努力工作.   昵称: ...

  3. BZOJ2553[BeiJing2011]禁忌——AC自动机+概率DP+矩阵乘法

    题目描述 Magic Land上的人们总是提起那个传说:他们的祖先John在那个东方岛屿帮助Koishi与其姐姐Satori最终战平.而后,Koishi恢复了读心的能力…… 如今,在John已经成为传 ...

  4. [BJOI2011]禁忌 --- AC自动机 + 矩阵优化 + 期望

    bzoj 2553 [BJOI2011]禁忌 题目描述: Magic Land上的人们总是提起那个传说:他们的祖先John在那个东方岛屿帮助Koishi与其姐姐Satori最终战平.而后,Koishi ...

  5. 【BZOJ2553】[BeiJing2011]禁忌 AC自动机+期望DP+矩阵乘法

    [BZOJ2553][BeiJing2011]禁忌 Description Magic Land上的人们总是提起那个传说:他们的祖先John在那个东方岛屿帮助Koishi与其姐姐Satori最终战平. ...

  6. 【bzoj2553】[BeiJing2011]禁忌

    2553: [BeiJing2011]禁忌 Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 595  Solved: ...

  7. [BZOJ2553][BeiJing2011]禁忌 dp+AC自动机+矩阵快速幂

    2553: [BeiJing2011]禁忌 Time Limit: 20 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 1206  Solved ...

  8. 【Mood-14】龙虎榜 活跃在github中的1000位中国开发者

    Last cache created on 2015-01-07 by Github API v3. ♥ made by hzlzh just for fun. Rank Gravatar usern ...

  9. BZOJ - 2553 :禁忌(AC自动机+贪心+奇怪的矩阵)

    Magic Land上的人们总是提起那个传说:他们的祖先John在那个东方岛屿帮助Koishi与其姐姐Satori最终战平.而后,Koishi恢复了读心的能力…… 如今,在John已经成为传说的时代, ...

随机推荐

  1. struts整合spring整合hibernate

    1, web.xml中配置spring监听类 <listener> <listener-class>org.springframework.web.context.Contex ...

  2. 简单好用的Adapter---ArrayAdapter

    简单好用的Adapter---ArrayAdapter 拖延症最可怕的地方就是:就算自己这边没有拖延,但对方也会拖延,进而导致自己这边也开始拖延起来!现在这个项目我这边已经是完工了,但是对方迟迟没有搞 ...

  3. 子PID namespace中获取父namespace中pid的方法

    在那篇< 使用独立PID namespace防止误杀进程>中的最后,我碰到了一个难题,那就是父PID namespace中的进程无法使用进入子PID namespace中通过echo $$ ...

  4. POJ 1013 小水题 暴力模拟

    Counterfeit Dollar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35774   Accepted: 11 ...

  5. Android系统移植(一)-让android系统在目标平台上运行起来

    编号),文件系统采用ubifs格式,控制台设备为ttyS1,波特率为115200 启动的第一个应用程序是/init (6)确保控制台的设置和硬件保持一致,如:硬件上串口用的是UART1,则内核启动参数 ...

  6. android 豆瓣客户端 视频

    链接如下:http://download.csdn.net/detail/jltxgcy/5667337

  7. 【APEX初步】【2】【sObjects与数据库】

    由于apex是与数据库集成的.我们可以直接用apex访问数据库.每条记录就是一个SObject对象

  8. codewars-random(3)

    思路:两个嵌套的for循环(不推荐,应该有更好的.) 具体代码:function longestConsec(strarr, k) {    // your code    var n = strar ...

  9. 百度的hao123.com篡改浏览器首页,解决办法

    快捷方式右键找到chrome.exe, 把chorme.exe修改成别的名字例如 chromeFuckHao123.exe 就OK了. hao123是用病毒的形式查找chrome.exe然后进程注入的 ...

  10. iOS Quartz2D画图

    对于刚接触Quartz2D的同学来说,先了解 上下文 的概念,再从最基础的画线来具体体验Quartz2D的画图步骤 介绍Quart2D :是苹果官方的二维(平面)绘图引擎,同时支持iOS和macOS系 ...