题目:

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. JS中事件绑定函数,事件捕获,事件冒泡

    1 事件绑定:事件与函数绑定以及怎么取消绑定 1.1 元素.onclick这种形式,如下: <div id="div1">aaa</div> <scr ...

  2. 私有仓库 gitlab 部署笔记

    --------------------------------------------gitlab简介------------------------------------------------ ...

  3. Windows安装MongoDB 4.0并赋予用户访问权限

    第一部分 Windows安装MongoDB-4.0 第一步:下载MongoDB:https://www.mongodb.com/download-center?jmp=nav#community 我目 ...

  4. 接口测试(jmeter和postman 接口使用)

    接口测试基础知识 接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点.把前端(client)和后端(server)联系起来,测试的重点是要检查数据的交换,传递和控制管理过程,以及系统 ...

  5. 结巴分词出现AttributeError: 'float' object has no attribute 'decode'错误

    将data转变为str格式 inputfile = 'comment2.csv'outputfile = 'comment2_cut.txt'datas = pd.read_csv(inputfile ...

  6. 「Algospot」量化QUANTIZE

    一道不难的DP题,主要是为了总结这类最优化题的思路:同时还学到了一个新操作 传送门:$>here<$ 题意 给出一个长度为$N$的序列,要求最多使用s个数字进行量化(有损压缩),即代替原数 ...

  7. html-webpack-plugin不输出script标签的方法

    那就是修改源码 约550行: if (!this.options.disableScript) { if (this.options.inject === 'head') { head = head. ...

  8. <el-upload></el-upload>组件上传图片到七牛云

    [01]搭建好页面结构.定义数据与接口 <el-upload method="post" ref="upload" :action="domai ...

  9. css解决内联元素间的空白间隔

    在内联元素的父级元素上设置font-size: 0px;即可.例如: <div class="wrap"> <ul> <li class=" ...

  10. 逆FizzBuzz问题求最短序列

    问题描述 FizzBuzz问题:一个大于0的自然数能整除3,将输出“Fizz”:能整除5,将输出“Buzz”:能整除3和5,将输出“FizzBuzz”:否则输出自己. 逆FizzBuzz问题最短序列: ...