Tom wants to cover a rectangular floor by identical L-shape tiles without overlap. As shown below, the floor can be split into many small squares, and the L-shape tile consists of exactly four small squares. The floor of 3*8 can be completely covered by
Tom would like to know whether an arbitrary floor with n*m small squares can be completely covered or not. He is sure that when n and m are small he can find the answer by paper work, but when it comes to larger n and m, he has no idea to find the answer. Can you tell him?
The input file will consist of several test cases. Each case consists of a single line with two positive integers m and n (1<=m<=15, 1<=n<=40).
The input is ended by m=n=0.
For each case, print the word ‘YES’ in a single line if it is possible to cover the m*n floor, print ‘NO’ otherwise.
3 8 3 7 0 0
YES NO
雖然題目“看起來”有點不好想,其實很簡單的一道題,只要搞清楚L型與面積的關係就可以
#include<stdio.h>
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
if(n==0||m==0) break;
else if(n*m%8==0&&n>1&&m>1) printf("YES\n");
else printf("NO\n");
}
return 0;
}