题目:

ZOJ 1008

分析:

重排矩阵, 虽然题目给的时间很多, 但是要注意剪枝, 把相同的矩阵标记, 在搜索时可以起到剪枝效果。

Code:

#include <bits/stdc++.h>

using namespace std;

struct Node {
int left, right, top, buttom;
bool operator == (const Node &a) const {
return left == a.left && right == a.right && top == a.top && buttom == a.buttom;
}
}; Node E[35];
int Sum[35], Map[11][11], Num; void GetE(int n) {
memset(Sum, 0, sizeof(Sum));
for(int i = 0; i < n*n; ++i) {
cin >> E[i].top >> E[i].right >> E[i].buttom >> E[i].left;
for(int j = 0; j <= i; ++j) {
if(E[j] == E[i]) {
Sum[j]++;
break;
}
}
}
} bool DFS(int pos, int n) {
if(pos == n*n) return true;
int x = pos/n, y = pos%n;
//cout << x << " " << y << endl;
for(int i = 0; i < n*n; ++i) {
if(Sum[i]) {
if(x > 0 && E[i].top != E[Map[x-1][y]].buttom) continue;
if(y > 0 && E[i].left != E[Map[x][y-1]].right) continue;
Map[x][y] = i;
--Sum[i];
if(DFS(pos+1, n) == true) return true;
else {
++Sum[i];
}
}
}
return false;
} int main() {
int Case = 0;
while(cin >> Num && Num) {
if(Case > 0) printf("\n");
GetE(Num);
//cout << "1" <<endl;
if(DFS(0, Num)) printf("Game %d: Possible\n", ++Case);
else printf("Game %d: Impossible\n", ++Case);
}
return 0;
}

ZOJ1008的更多相关文章

  1. ZOJ1008 Gnome Tetravex

    DFS+剪枝~ #include<bits/stdc++.h> using namespace std; ][]; int N; int cnt; ]; ]; unordered_map& ...

  2. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

  3. Gnome Tetravex

    zoj1008:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1008 题目意思是有一个游戏,即给出一个图,该图是由n*n个 ...

随机推荐

  1. 一入OI深似海 4 —— 纪念我最后一次PJ(中)

    不知道怎么回事,直到比赛前10分钟才放我们进考场. 考场在体育馆里面,很大很壮观. 我匆匆忙忙地找到位子,屁股还没坐热,被老师告知不能带水. what?! 于是我只好把水放在统一放私人物品的地方. 电 ...

  2. iOS 枚举 初体验

    iOS枚举 我的code /*文件名 SC_CDV_OCR.m*/ typedef enum _OCRResultState { OCRResultStateOK = 1, OCRResultStat ...

  3. linux环境下在springboot项目中获取项目路径(用于保存文件等)

    //application.properties中设置:(file.path=static/qrfile/)//保存到static文件夹下的qrfile目录@Value("${file.pa ...

  4. MarkdownPad

    MarkdownPad Markdown编辑器,只能在windows下使用 下载地址 :http://markdownpad.com/ 破解: 邮箱:Soar360@live.com 授权证书 GBP ...

  5. [2019.03.21]LF, CR, CRLF and LFCR(?)

    开玩笑的啦,没有LFCR这种沙雕东西 为什么突然想起来写这个呢,是因为先前照着shell画llehs的时候,总报错,改正了以后又因为看不见而在上一篇博客上没有写明,所以过来好好写一写咯. 可以看出报错 ...

  6. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  7. python并发编程之IO阻塞基础知识点

    IO模型 解决IO问题的方式方法 问题是:IO操作阻塞程序执行 解决的也仅仅是网络IO操作   一般数据传输经历的两个阶段,如图: IO阻塞模型分类: 阻塞IO 非阻塞IO 多路复用IO 异步IO(爬 ...

  8. bash中打印文件每一行及其行号

    #!/bin/bash linenumber=$(cat remoteIP.cfg |wc -l) currentline= for ip in $(cat remoteIP.cfg) do curr ...

  9. 洛谷P3268 [JLOI2016]圆的异或并(扫描线)

    扫描线还不是很熟啊--不管是从想的方面还是代码实现的方面-- 关于这题,考虑一条平行于\(y\)轴的扫描线从左到右扫描每一个圆,因为只有相离和内含两种关系,只用在切线处扫描即可 我们设上半圆为1,下半 ...

  10. NOIP 2019 RP++

    \[\huge NOIP^{2019}_{RP++}\] \[\huge NOIP^{2019}_{Score++}\]