您的位置:首页 > 大数据 > 人工智能

Black and white painting

2012-03-10 16:23 337 查看

Blackandwhitepainting

TimeLimit:1000MSMemorylimit:65536K

题目描述

YouarevisitingtheCentrePompidouwhichcontainsalotofmodernpaintings.Inparticularyounoticeonepaintingwhichconsistssolelyofblackandwhitesquares,arrangedinrowsandcolumnslikeinachessboard(notwoadjacentsquareshavethesamecolour).Bytheway,theartistdidnotusethetoolofproblemAtocreatethepainting.

Sinceyouarebored,youwonderhowmany8×8chessboardsareembeddedwithinthispainting.Thebottomrightcornerofachessboardmustalwaysbewhite.

输入

Theinputcontainsseveraltestcases.Eachtestcaseconsistsofonelinewiththreeintegersn,mandc.(8≤n,m≤40000),wherenisthenumberofrowsofthepainting,andmisthenumberofcolumnsofthepainting.cisalways0or1,where0indicatesthatthebottomrightcornerofthepaintingisblack,and1indicatesthatthiscorneriswhite.

Thelasttestcaseisfollowedbyalinecontainingthreezeros.

输出

Foreachtestcase,printthenumberofchessboardsembeddedwithinthegivenpainting.

示例输入

880
881
991
40000399990
000


示例输出

0
1
2
799700028






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

*/
#include<stdio.h>
#include<string.h>
intmain()
{
longn,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);
}
return0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: