zoj2479 Cover the Rectangular Ground
肯定是dfs搜一下的,但是呢存在一个很大的剪枝,也就是面积必定要是相等的,那么如何去操作呢,可以想到的是二进制枚举选取的方法,然后把方法中选取的矩形面积求和并判断一下即可,然后dfs搜索,要注意的是,需要维持现状的变量在变化之前一定要记录,要变回来时,一定要变回来,另外在dfs中还可以判断覆盖是否合理,以及是否已经没有可找到的空白区域。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 2005
#define ull unsigned long long
#define ll long long
#define hashmod 99999839
#define mod 9997
int T,n,m,q,x[],y[],p[],sx,sy,b;
int a[][];
bool f[],ans;
bool overlap(int i,int v,int t){
int ex = x[i],ey = y[i];
if(v) swap(ex,ey);
if(sx + ex - >= n || sy + ey - >= m) return false;
for(int j = sx;j < sx + ex;++j){
for(int k = sy;k < sy + ey;++k){
if(t && a[j][k]) return false;
}
}
for(int j = sx;j < sx + ex;++j){
for(int k = sy;k < sy + ey;++k){
a[j][k] = t;
}
}
return true;
}
bool findempty(){
for(int i = sx;i < n;++i){
for(int j = ;j < m;++j){
if(!a[i][j]){
sx = i,sy = j;
return true;
}
}
}
return false;
}
bool check(){
for(int i = ;i < n;++i){
for(int j = ;j < m;++j){
if(!a[i][j]) return false;
}
}
return true;
}
void dfs(){
bool flag = false;
for(int i = ;i < q;++i){
if((b & p[i]) && !f[i]){
flag = true;
f[i] = true;
int tx = sx,ty = sy;
if(overlap(i,,)){
if(findempty()) dfs();
else{
ans = true;
return;
}
if(ans) return;
sx = tx,sy = ty;
overlap(i,,);
}
if(!overlap(i,,)){
f[i] = false;
continue;
}
if(findempty()) dfs();
else{
ans = true;
return;
}
if(ans) return;
sx = tx,sy = ty;
overlap(i,,);
f[i] = false;
}
}
if(!flag && check()) ans = true;
}
bool solve(){
for(int i = ;i < p[q];++i){//枚举选取哪一些
int s = ;
for(int j = ;j < q;++j){
if(i & p[j]) s = s + x[j] * y[j];
}
if(s != n * m) continue;
b = i;
ans = false;
sx = sy = ;
dfs();
if(ans) return true;
}
return false;
}
int main(){
/*submit failed*/
/*submit failed*/
/*submit failed*//*submit failed*//*submit failed*/
freopen("a.in","r",stdin);
freopen("b.out","w",stdout);
cin >> T;
p[] = ;
for(int i = ;i <= ;++i) p[i] = p[i - ] << ;
while(T--){
scanf("%d%d",&n,&m);
cin >> q;
for(int i = ;i < q;++i){
scanf("%d%d",&x[i],&y[i]);
}
memset(a,,sizeof(a));
memset(f,false,sizeof(f));
if(solve()) puts("YES");
else puts("NO");
}
return ;
}
zoj2479 Cover the Rectangular Ground的更多相关文章
- Entity Framework 6 Recipes 2nd Edition(11-12)译 -> 定义内置函数
11-12. 定义内置函数 问题 想要定义一个在eSQL 和LINQ 查询里使用的内置函数. 解决方案 我们要在数据库中使用IsNull 函数,但是EF没有为eSQL 或LINQ发布这个函数. 假设我 ...
- HBase 数据模型(Data Model)
HBase Data Model--HBase 数据模型(翻译) 在HBase中,数据是存储在有行有列的表格中.这是与关系型数据库重复的术语,并不是有用的类比.相反,HBase可以被认为是一个多维度的 ...
- 城市边界线预测(根据灯光指数)(PUL)
1.EXEALL.m function EXEALL(FilePath, FileName)%执行所有流程% FilePath: 文件夹所在路径% FileName: 文件夹名称 FullPath = ...
- poj 1266 Cover an Arc.
http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
- UVALive 3959 Rectangular Polygons (排序贪心)
Rectangular Polygons 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/G Description In thi ...
- poj 2836 Rectangular Covering
Rectangular Covering Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2776 Accepted: 7 ...
- Dancing Links and Exact Cover
1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...
- img及父元素(容器)实现类似css3中的background-size:contain / background-size:cover
img及父元素(容器)实现类似css3中的background-size:contain / background-size:cover <!DOCTYPE html> <html ...
- 集合覆盖 顶点覆盖: set cover和vertex cover
这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...
随机推荐
- AJPFX总结IO流中的缓冲思想
缓冲思想 (因为内存的运算速度要远大于硬盘的原酸速度,所以只要降低硬盘的读写次数,就可以提高效率) 1. 字节流一次读写一个数组的速度明显比一次读写一个字节的速度快很多, 2. 这是加 ...
- P1603 斯诺登的密码
题目背景 根据斯诺登事件出的一道水题 题目描述 题目描述 2013年X月X日,俄罗斯办理了斯诺登的护照,于是他混迹于一架开往委内瑞拉的飞机.但是,这件事情太不周密了,因为FBI的间谍早已获悉他的具体位 ...
- 微信小程序组件解读和分析:十二、picker滚动选择器
picker滚动选择器组件说明: picker: 滚动选择器,现支持三种选择器,通过mode属性来区分, 分别是普通选择器(mode = selector),时间选择器(mode = time),日期 ...
- Godaddy域名301跳转问题处理
前言:Godaddy的域名301跳转一共有六步,详情见以下步骤: 第一步: 第二步:找到你的域名,并点击DNS 第三步:点击添加 第四步:添加解析ip地址 第五步:域名转址,也就是301跳转 第六步: ...
- 从Code::Blocks到Dev–C++,Dev-C++安装调试一条龙
关于单文件调试 Codeblocks只支持单文件编译,不支持单文件调试,只有整个工程才能调试,还有路径名里不能有中文和空格,很坑的!就因为这个弃用了. 去你的吧! 老子用别的了 谁支持单文件编译和调试 ...
- vs code 用户代码片段 html.json
{ // Place your snippets for html here. Each snippet is defined under a snippet name and has a p ...
- Spring.Boot.1 -- 概览
Spring Boot 是如何简化Java 开发的 SpringBoot的一些重要特征 长久以来,Spring 框架作为Java应用开发的框架地位稳固.最近在云计算.大数据.无结构数据持续化.函数式反 ...
- Bootstrap table的基础用法
一.官方文档 Bootstrap 中文网:http://www.bootcss.com/ Bootstrap Table 中文网 : http://bootstrap-table.wenzhixin. ...
- 【牛客小白月赛6】 J 洋灰三角 - 快速幂&逆元&数学
题目地址:https://www.nowcoder.com/acm/contest/136/J 解法一: 推数学公式求前n项和: 当k=1时,即为等差数列,Sn = n+pn(n−1)/2 当k≠1时 ...
- MySql-count(*)与count(id)与count(字段)之间的执行结果和性能分析
在mysql数据库中,当我们需要统计数据的时候,一定会用到count()这个方法,那么count(值)里面的这个值,到底应该怎么选择呢!常见有3种选择,(*,数字,列名),分别列出它们的执行结果和性能 ...