UVA - 12113 Overlapping Squares(重叠的正方形)
2024-10-08 17:14:35
题意:给定一个4*4的棋盘和棋盘上所呈现出来的纸张边缘,问用不超过6张2*2的纸能否摆出指定的形状。
分析:2*2的纸在4*4的棋盘上总共有9种放置位置,枚举所有的放置位置即可。枚举情况总共种。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, -1, 0, 1, -1, -1, 1, 1};//西北东南
const int dc[] = {-1, 0, 1, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-15;
const int MAXN = 10 + 10;
const int MAXT = 10000 + 10;
using namespace std;
char pic[MAXN][MAXN];
char p1[MAXN][MAXN];
int vis[MAXN];
bool judge(){//判断是否摆成目标形状
for(int i = 0; i < 5; ++i){
for(int j = 0; j < 9; ++j){
if(pic[i][j] != p1[i][j]) return false;
}
}
return true;
}
bool dfs(int step){
if(judge()) return true;
if(step >= 6) return false;
char p2[MAXN][MAXN];
memcpy(p2, p1, sizeof p1);//p2便于恢复p1数组内容
for(int i = 0; i < 9; ++i){//枚举2*2正方形可以放置的9个位置
if(!vis[i]){
vis[i] = 1;
int r = i / 3;
int c = 2 * (i % 3) + 1;
p1[r][c] = p1[r][c + 2] = p1[r + 2][c] = p1[r + 2][c + 2] = '_';
p1[r + 1][c - 1] = p1[r + 2][c - 1] = p1[r + 1][c + 3] = p1[r + 2][c + 3] = '|';
p1[r + 1][c] = p1[r + 1][c + 1] = p1[r + 1][c + 2] = p1[r + 2][c + 1] = ' ';
if(dfs(step + 1)) return true;
vis[i] = 0;
memcpy(p1, p2, sizeof p1);
}
}
return false;
}
int main(){
int kase = 0;
while(gets(pic[0]) != NULL){
if(pic[0][0] == '0') return 0;
memset(vis, 0, sizeof vis);
for(int i = 1; i < 5; ++i){
gets(pic[i]);
}
printf("Case %d: ", ++kase);
for(int i = 0; i < 5; ++i){
for(int j = 0; j < 9; ++j){
p1[i][j] = ' ';
}
}
if(dfs(0)) printf("Yes\n");
else printf("No\n");
}
return 0;
}
最新文章
- linq To DataTable
- js计算两个日期的差值
- 利用百度词典API和Volley网络库开发的android词典应用
- 解决ArcGIS10.3属性表中文乱码问题
- CentOS6.5(Python-2.7.12)安装Pip
- mv、umask、chattr、lsattr命令
- Mac+IPAD上使用wireshark抓包
- dede 首页或列表页调用文章内容页body内容
- 百度地图 js api 实现 line 居中显示
- pycharm 常用快捷键操作
- [转载]tnsnames.ora监听配置文件详解
- 雷林鹏分享:使用 CSS 显示 XML
- Hadoop---集群之MySQL的安装
- js之表单记忆功能
- [Windows][C#][.NET][WPF]基于ArcFace2.0+红外双目摄像头的活体检测
- IT常用设备及服务器安全公告或漏洞地址pa安全预警微软安全公告 HP 安全公告AIX 安全公告REDHAT安全公告ORACLE 安全公告F5 安全公告 Cisco 安全公告Juniper 安全公告 VMware 安全公告IOS 安全公告
- Statistical Concepts and Market Returns
- 全面认识Docker和基本指令
- myeclipse安装SVN插件方法
- C# TTS-文本转语音