1692. Cover

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 6 L-shape tiles, but the floor of 3*7 is impossible.

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;
     }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章