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

sdutoj 2373 Black and white painting( 规律统计计算 3Y )

时间:2015-02-02 09:24:20      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

Black and white painting

题目描述

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

  代码:

  

#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>

using namespace std;

int main()
{
    int n, m, c;
    long long int ans=0;
    int i, j;

    while(scanf("%d %d %d", &n, &m, &c)!=EOF)
    {
        if(n==0 && m==0 &&c==0 )
            break;
        ans=0;
        int flag;
        if(c==1) // bai
            flag=1;
        else
            flag=0;
        int dd, ff;
        for(i=m; i>=8; i--)
        {
            if(flag==1)
            {
                dd=(n-8)/2+1;
                ans+=dd; flag=0;
            }
            else
            {
                ff=n-1;
                if(ff<8)
                {
                    dd=0;
                    ans+=dd;
                    flag=1;
                }
                else
                {
                    dd=(ff-8)/2+1;
                    ans+=dd; flag=1;
                }
            }
        }
        printf("%lld\n", ans );
    }
    return 0;
}

 

sdutoj 2373 Black and white painting( 规律统计计算 3Y )

标签:

原文地址:http://www.cnblogs.com/yspworld/p/4266760.html

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