码迷,mamicode.com
首页 > 其他好文 > 详细

zoj3678The Toy of Flandre Scarlet(水,高中老师提过。。)

时间:2014-05-15 07:06:45      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:水题

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.

bubuko.com,布布扣

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?

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


题目大意:题目意思是给你一个cube,他的长宽高,l,w,h,然后总共有l*w*h个格子,每个格子上面上有一个数字,然后可以每次可以操作,使得两个相邻的格子里的数字同时加上一个数字或者同时减去一个数字。问你操作次数不限定,能否使得cube数字全为0。

    记得高中那会儿玩儿魔方的时候,下课了一个老师问过我这个问题,魔方的每个格子有数,相邻的可加加减减,归零的条件只需要八个顶角加上六个面心的和等于十二个棱角加上核的和即可。

其实可以简单的画一个二维的3*3的
1 0 1
0 1 0
1 0 1
其实我们不管怎么对这个图处理,四个角加上中心点的和减去四条边上的和的值始终等于5。
因为我们可以对每个点分类,每次都是这两类的同加同减,他们的差不变,自己体会。。


AC代码:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
    int cnt1,cnt2;

    int i,j,k,l,w,h;

    while(cin>>l>>w>>h)
    {
        cnt1=cnt2=0;
        int x;
        for(i=0;i<l;i++)
            for(j=0;j<w;j++)
                for(k=0;k<h;k++)
                {
                    cin>>x;
                    if((i+j+k)&1) cnt1+=x;
                    else cnt2+=x;
                }

        if(cnt1==cnt2) puts("Yes");
        else puts("No");
    }
    return 0;
}

/*
1 1 1
1

2 2 2
1 1
1 1
1 1
1 1
*/



zoj3678The Toy of Flandre Scarlet(水,高中老师提过。。),布布扣,bubuko.com

zoj3678The Toy of Flandre Scarlet(水,高中老师提过。。)

标签:水题

原文地址:http://blog.csdn.net/coraline_m/article/details/25742187

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!