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[][]; int main() {
bool cur = ;
for (int i = ; i <= ; i ++) {
for (int j = ; j <= ; j ++) {
mp[i][j] = cur;
if (j != ) cur = !cur;
}
}
int a, b, c, d;
int T, _t = ;
scanf("%d", &T);
while (T --) {
printf("Scenario #%d:\n", _t ++);
scanf("%d %d %d %d", &a, &b, &c, &d);
if (mp[a][b] == mp[c][d]) printf("0\n\n");
else printf("1\n\n");
} return ;
}

POJ2495(棋盘分治,染色)的更多相关文章

  1. HDU 5402 Travelling Salesman Problem(棋盘染色 构造 多校啊)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5402 Problem Description Teacher Mai is in a maze wit ...

  2. BZOJ2706 : [SDOI2012]棋盘覆盖

    A类数据: 将棋盘黑白染色,相邻的点之间连边,求出二分图最大匹配即可. B类数据: 答案为$\lfloor\frac{n^2-1}{3}\rfloor$,用FFT加速计算即可,时间复杂度$O(L\lo ...

  3. CODEVS 2171 棋盘覆盖

    2171 棋盘覆盖 给出一张nn(n<=100)的国际象棋棋盘,其中被删除了一些点,问可以使用多少12的多米诺骨牌进行掩盖. 错误日志: 直接在模板上调整 \(maxn\) 时没有在相应邻接表数 ...

  4. 【P3355】骑士共存问题(最大流+黑白染色,洛谷)

    这个题刚看上去就让人不禁想到一道叫做方格取数问题的题目,事实上也就是这么做,对棋盘黑白染色,然后黑格子连源点,白的连汇点,点权为1.然后判断一下黑格子能影响到的白格子,边权为inf,跑一遍最大流就可以 ...

  5. [JOYOI] 1035 棋盘覆盖

    题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Local 题目描述 给出一张nn(n<=100)的国际象棋棋盘,其中被删除了一些点,问可以使用多 ...

  6. 「CH6801」棋盘覆盖

    「CH6801」棋盘覆盖 传送门 考虑将棋盘黑白染色,两个都无障碍的相邻的点之间连边,边的容量都为1,然后就求一次最大匹配即可 参考代码: #include <cstring> #incl ...

  7. POJ2466 棋盘覆盖

    一张\(n*m\)的棋盘,有\(k\)个点不能被覆盖,问其余点能不能被\(1*2\)的小矩形完全覆盖,多测 这题先输入\(m\)是什么鬼啊!!! 其实是一个比较裸的二分图判定,把\(k\)个点挖去然后 ...

  8. BZOJ 2127: happiness [最小割]

    2127: happiness Time Limit: 51 Sec  Memory Limit: 259 MBSubmit: 1815  Solved: 878[Submit][Status][Di ...

  9. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

随机推荐

  1. PM所该学习的

     最近第二阶段实在大家都是大一大二,面临的考试很多也很难,很多时候就开始松懈了下来.可是做事情就是需要效率和时间,慢慢地,也开始懈怠了下来. 作为pm,首先自己必须比组员先了解云笔记的各种进程,做好沟 ...

  2. lintcode-64-合并排序数组 II

    64-合并排序数组 II 合并两个排序的整数数组A和B变成一个新的数组. 注意事项 你可以假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B中的元素. 样例 给出 A = [1, 2, 3, ...

  3. [剑指Offer] 22.从上往下打印二叉树

    [思路]广度优先遍历,队列实现 class Solution { public: vector<int> PrintFromTopToBottom(TreeNode* root) { qu ...

  4. Delphi xe7组件和控件的安装方法

    暂时我所遇到的所有控件安装方法大体与下面两种相同. 若有不同大家提出来,一起想办法解决. .dproj格式的组件安装方法: raise组件 安装详细步骤如下: 一.设置搜索路径1. 将本包中的文件连同 ...

  5. POJ——2449 Remmarguts' Date

    Description "Good man never makes girls wait or breaks an appointment!" said the mandarin ...

  6. sql如何先排序再去重

    场景 有一张得分表(score),记录了用户每次的得分,同一个人可能有多个得分. id name score 1 tom 45 2 jack 78 3 tom 34 . . . 需求:找出分数最高的前 ...

  7. bootstrap-table 增加序号列(支持分页)

    columns: [ { checkbox: true }, { title: '序号', align: 'center', halign: 'center', formatter: function ...

  8. CTSC2018 & APIO2018 颓废 + 打铁记

    CTSC2018 & APIO2018 颓废 + 打铁记 CTSC 5 月 6 日 完美错过报道,到酒店领了房卡放完行李后直接奔向八十中拿胸牌.饭票和资料.试机时是九省联考的题,从来没做过,我 ...

  9. [洛谷P4722]【模板】最大流 加强版 / 预流推进

    会$TLE$... C++ Code:(HLPP) #pragma GCC optimize(3) #pragma GCC optimize("unroll-loops") #in ...

  10. [NOI.AC省选模拟赛3.23] 集合 [数学]

    题面 传送门 一句话题意: 给定$n\leq 1e9,k\leq 1e7,T\leq 1e9$ 设全集$U=\lbrace 1,2,3,...n\rbrace $,求$(min_{x\in S}\lb ...