题意:给定一个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;
}

  

最新文章

  1. linq To DataTable
  2. js计算两个日期的差值
  3. 利用百度词典API和Volley网络库开发的android词典应用
  4. 解决ArcGIS10.3属性表中文乱码问题
  5. CentOS6.5(Python-2.7.12)安装Pip
  6. mv、umask、chattr、lsattr命令
  7. Mac+IPAD上使用wireshark抓包
  8. dede 首页或列表页调用文章内容页body内容
  9. 百度地图 js api 实现 line 居中显示
  10. pycharm 常用快捷键操作
  11. [转载]tnsnames.ora监听配置文件详解
  12. 雷林鹏分享:使用 CSS 显示 XML
  13. Hadoop---集群之MySQL的安装
  14. js之表单记忆功能
  15. [Windows][C#][.NET][WPF]基于ArcFace2.0+红外双目摄像头的活体检测
  16. IT常用设备及服务器安全公告或漏洞地址pa安全预警微软安全公告 HP 安全公告AIX 安全公告REDHAT安全公告ORACLE 安全公告F5 安全公告 Cisco 安全公告Juniper 安全公告 VMware 安全公告IOS 安全公告
  17. Statistical Concepts and Market Returns
  18. 全面认识Docker和基本指令
  19. myeclipse安装SVN插件方法
  20. C# TTS-文本转语音

热门文章

  1. Linux文件系统层次结构标准FHS
  2. MAC Matlab 中文乱码
  3. P1091合唱队形(LIS问题)
  4. matlab练习程序(概率路线图PRM)
  5. 「NOIP2013」华容道
  6. Java枚举类型enum使用详解
  7. 无线渗透--wifiphisher之wifi钓鱼获取wifi密码
  8. NO25 三剑客之SED行天下
  9. CentOS7 环境下 在Hadoop集群安装Hive
  10. P1078 字符串压缩与解压