toj 1709 Incomplete chess boards

1709.   Incomplete chess boards
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 320    Accepted Runs: 199    Multiple test files



Background

Tom gets a riddle from his teacher showing 42 chess boards from each of which two squares are removed. The teacher wants to know which boards can be completely covered by 31 dominoes. He promises ten bars of chocolate for the person who solves the problem correctly. Tom likes chocolate, but he cannot solve this problem on his own. So he asks his older brother John for help. John (who likes chocolate as well) agrees, provided that he will get half the prize.

John's abilities lie more in programming than in thinking and so decides to write a program. Can you help John? Unfortunately you will not win any bars of chocolate, but it might help you win this programming contest.

Problem

You are given are 31 dominoes and a chess board of size 8 * 8, two distinct squares of which are removed from the board. The square in row a and column b is denoted by (a, b) with a, b in {1, . . . , 8}.

A domino of size 2 * 1 can be placed horizontally or vertically onto the chess board, so it can cover either the two squares {(a, b), (a, b + 1)} or {(b, a), (b + 1, a)} with a in {1, . . . , 8} and b in {1, . . . , 7}. The object is to determine if the so-modified chess board can be completely covered by 31 dominoes.

For example, it is possible to cover the board with 31 dominoes if the squares (8, 4) and (2, 5) are removed, as you can see in Figure 1.

 

Input

The first input line contains the number of scenarios k. Each of the following k lines contains four integers a, b, c, and d, separated by single blanks. These integers in the range {1, . . . , 8} represent the chess board from which the squares (a, b) and (c, d) are removed. You may assume that (a, b) ≠ (c, d).

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print the number 1 if the board in this scenario can be completely covered by 31 dominoes, otherwise write a 0. Terminate the output of each scenario with a blank line.

Sample Input

3
8 4 2 5
8 8 1 1
4 4 7 1

 

Sample Output

Scenario #1:
1
Scenario #2:
0
Scenario #3:
0

 



Source: TUD Programming Contest 2005
Submit   List    Runs   Forum   Statistics

#include  < iostream >
#include 
< cmath >
using   namespace  std;
int  t;
int  main()
{
    cin
>> t;
    
int  zz = 1 ;
    
while (t -- )
    {
        
int  a,b,c,d;
        cin
>> a >> b >> c >> d;
        
int  sum = abs(c - a) + abs(d - b);
        printf(
" Scenario #%d:\n " ,zz ++ );
        
if (sum % 2 )
            printf(
" 1\n\n " );
        
else
            printf(
" 0\n\n " );
    }
    
return   0 ;
}

转载于:https://www.cnblogs.com/forever4444/archive/2009/05/16/1458416.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值