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;
}
相关文章推荐
- poj 3364 Black and white painting
- poj 3364 Black and white painting
- sdutoj 2373 Black and white painting( 规律统计计算 3Y )
- 杂码系列之 Black and white painting hdoj 1802
- Poj 3364 Black and white painting
- HDU 1802 || SDUT 2373 Black and white painting(规律)
- POJ 3364 Black and white painting 再想想
- hdu 1802 Black and white painting(置换群)
- UVa 11231 - Black and white painting
- HDU 5113 Black And White(dfs)
- 玲珑杯 1091 - Black and White(dp计数)
- 1227: Gang Black and Gang White
- hdu 3911 Black And White(线段树)
- Abort black hat and white hat
- Off-White x Nike Air VaporMax White and Black Launching in 2018
- 玲珑学院OJ 1091 Black and White【dp+前缀和】经典模型
- hdu 5113 Black And White (dfs+剪枝)
- HDU 5113 Black And White(深搜+剪枝)
- dfs-hdu 5113 Black And White
- 文章标题 HDU 5583:Kingdom of Black and White(暴力+代码实现能力)