zoukankan      html  css  js  c++  java
  • ****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 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,不过有人已经这样干过于是只能排第二了。

    代码:

     1 #include <stdio.h>
     2 
     3 int l, w, h;
     4 int sum[2];
     5 
     6 int main()
     7 {
     8     int t, i, j, k;
     9     while(scanf("%d%d%d", &l, &w, &h) != EOF)
    10     {
    11         sum[1] = sum[0] = 0;
    12         for(i=0; i<l; ++i)
    13         {
    14             for(j=0; j<w; ++j)
    15             {
    16                 for(k=0; k<h; ++k)
    17                 {
    18                     scanf("%d", &t);
    19                     sum[(i+j+k)%2] += t;//根据该点距离原点的距离进行奇偶分类。
    20                 }
    21             }
    22         }
    23         if(sum[0] == sum[1])
    24             printf("Yes
    ");
    25         else
    26             printf("No
    ");
    27     }
    28     return 0;
    29 }
    View Code
  • 相关阅读:
    java新手的session初体验
    菜鸟身份看泛型
    Java初学者不可不知的MyEclipse的设置技巧(自动联想功能)
    GCT之数学公式(几何部分)
    GCT之数学公式(代数部分)
    GCT之语文细节知识
    单元测试的方法
    常用的测试方法
    SQL 经典语句大全
    待处理(一)
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3455111.html
Copyright © 2011-2022 走看看