zoukankan      html  css  js  c++  java
  • POJ2495(棋盘分治,染色)

    Incomplete chess boards
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 2483   Accepted: 1519

    Description

    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, Darmstadt, Germany
     
    题意:8*8的棋盘中去掉两个点,如果能用1*2的长方形铺满输出1,否则输出0
    思路:二分图匹配是这一类问题的通解,但这题有特殊做法,对棋盘染色,如果去掉的两个点颜色相同则无法铺满,否则可以铺满
    /*
    ID: LinKArftc
    PROG: 2495.cpp
    LANG: C++
    */
    
    #include <map>
    #include <set>
    #include <cmath>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <cstdio>
    #include <string>
    #include <utility>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define eps 1e-8
    #define randin srand((unsigned int)time(NULL))
    #define input freopen("input.txt","r",stdin)
    #define debug(s) cout << "s = " << s << endl;
    #define outstars cout << "*************" << endl;
    const double PI = acos(-1.0);
    const double e = exp(1.0);
    const int inf = 0x3f3f3f3f;
    const int INF = 0x7fffffff;
    typedef long long ll;
    
    int mp[10][10];
    
    int main() {
        bool cur = 0;
        for (int i = 1; i <= 8; i ++) {
            for (int j = 1; j <= 8; j ++) {
                mp[i][j] = cur;
                if (j != 8) cur = !cur;
            }
        }
        int a, b, c, d;
        int T, _t = 1;
        scanf("%d", &T);
        while (T --) {
            printf("Scenario #%d:
    ", _t ++);
            scanf("%d %d %d %d", &a, &b, &c, &d);
            if (mp[a][b] == mp[c][d]) printf("0
    
    ");
            else printf("1
    
    ");
        }
    
        return 0;
    }
  • 相关阅读:
    C/C++中浮点数输出格式问题
    C/C++中的输出对齐设置
    C++11 中的initialize_list
    c++中的构造函数初始化列表
    C++11中的array
    STL 中的链表排序
    poj1068 Parencodings
    poj 3295 Tautology
    How To Join XLA_AE_HEADERS and RCV_TRANSACTIONS(子分类账到事务处理追溯)
    销售订单的四个主要环节和每个环节用到的常用表
  • 原文地址:https://www.cnblogs.com/LinKArftc/p/4961745.html
Copyright © 2011-2022 走看看