zoukankan      html  css  js  c++  java
  • Black and white painting

    Black and white painting

    Time Limit: 1000MS Memory limit: 65536K

    题目描述

    You are visiting the Centre Pompidou which contains a lot of modern paintings. In particular you notice one painting which consists solely of black and white squares, arranged in rows and columns like in a chess board (no two adjacent squares have the same colour). By the way, the artist did not use the tool of problem A to create the painting.

    Since you are bored, you wonder how many 8 × 8 chess boards are embedded within this painting. The bottom right corner of a chess board must always be white.

    输入

    The input contains several test cases. Each test case consists of one line with three integers n, m and c. (8 ≤ n, m ≤ 40000), where n is the number of rows of the painting, and m is the number of columns of the painting. c is always 0 or 1, where 0 indicates that the bottom right corner of the painting is black, and 1 indicates that this corner is white.

    The last test case is followed by a line containing three zeros.

    输出

    For each test case, print the number of chess boards embedded within the given painting.

    示例输入

    8 8 0
    8 8 1
    9 9 1
    40000 39999 0
    0 0 0

    示例输出

    0
    1
    2
    799700028
     
     
     
     
    /*
    这道题是一道简单的数学题,只要看懂提意就好做了。
    由于棋盘的右下角的棋子颜色必须是已定下来的,白色的。(我忽略了一次然后WA了= =。。。)而且长宽均为8,
    所以右下角的棋子位置的区域是可以定下来的,即(m-7)*(n-7),又因为棋盘颜色只有黑白两种,所以棋子的位
    区域应该除以二,如果是以上的乘积得到是双数的话,无论右下角是什么颜色都是除以二,但是如果是单数的话,
    会因为右下角的颜色影响结果。画图看一下就知道了。(建议用2*2代替8*8,效果是一样的)

    */
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    long n,m,color,a;
    while(scanf("%ld%ld%ld",&n,&m,&color)&&n||m||color)
    {
    n = n-7;
    m = m-7;
    a = m*n/2;
    if(m%2&&n%2)//当得到的是一个奇数的时候(注意此处是m%2&&n%2,不能使两者相加,我因为这次WA了一次)
    a = a+color;
    printf("%ld\n",a);
    }
    return 0;
    }
    
    
  • 相关阅读:
    第2章 面试流程
    py面试指导系列-第1章 py服务端工程师面试指导
    十月的第一天
    I shall return
    k8S
    Eclipse编辑器基本设置
    Windows 下有什么软件能够极大地提高工作效率
    Bootstrap 轻量级后台管理系统模板--ACE使用介绍
    2014年将会受欢迎的IT技能--你有多少哪?
    面向程序员的数据库访问性能优化法则
  • 原文地址:https://www.cnblogs.com/0803yijia/p/2389250.html
Copyright © 2011-2022 走看看