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. SVN Access to '/svn/Test/!svn/me' forbidden,不能更新解决办法

    从之前的电脑将Repositorise复制到现在用的PC,出现可以checkout但是不能update的问题.在网上找到以下解决方法,均未能解决. 1.确认URL跟实际一致: 2.确认用户名密码正确: ...

  2. Entity Framework 之 Code First

    使用NuGet助您玩转代码生成数据————Entity Framework 之 Code First [前言] 如果是Code First老鸟或者对Entity Framework不感兴趣,就不用浪费 ...

  3. spring得到实例和new一个实例,哪个快?

    spring配置的bean是默认单例,那么在程序中,得到一个实例一定比创建一个实例的速度快,也更加省资源.今天实际测试的时候发现,new 一个对象比spring得到一个对象快多了.后面自己又加了个单例 ...

  4. 应用之星在线app开发平台,菜鸟也会做应用

    看着各类应用平台玲琅满目的应用,你是否幻想过,如果里面能有一款我开发的应用是件多NB的事,平凡的你肯定会说,我又不会设计又不会代码,怎么可能?现在告诉你,这不是幻想,即使你不会设计也不会代码,一样可以 ...

  5. 【OpenMesh】使用迭代器和循环机

    原文出处: http://openmesh.org/Documentation/OpenMesh-Doc-Latest/tutorial.html 这个例子展现: 如何使用迭代器 如何使用循环机 这个 ...

  6. [设计模式-创建型]工厂方法(Factory Method)

    概括 名称 Factory Method 结构 动机 定义一个用于创建对象的接口,让子类决定实例化哪一个类.Factory Method 使一个类的实例化延迟到其子类. 适用性 当一个类不知道它所必 ...

  7. 高反差保留滤镜学习OpenCV:滤镜系列(11)——高反差保留

    这几周笔者几篇文章介绍了改高反差保留滤镜的文章. 关联文章的地址 高反差保留就是高通滤波 r=(pix[x,y]-avg(R))/128 pix[x,y]*r+128*(1-r) #include & ...

  8. x86中的页表结构和页表项格式

    一.页表结构 分页转换功能由驻留在内存中的表来描述,该表称为页表(page table),存放在物理地址空间中.页表可看做简单的220个物理地址数组.线性到物理地址的映射功能可以简单地看做进行数组查找 ...

  9. .net Mongo Driver 1.0与2.0的对比与2.0的优化

    前言 最近闲的时间有点多,所以还是写博客吧. 有人说Mongo 2.0的写法难以把控,好多地方不知道咋用,所以坚持用1.0(不愿意去尝试2.0),我感觉不可理解.所以写篇博客比较下. Mongo C# ...

  10. JavaScript的对象与Json

    JSON有非常严格的语法,在string上下文里{ "prop": "val" } 是个合法的JSON,但{ prop: "val" }和{ ...