【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

先预处理出来一个正方形。
然后每次枚举新加的正方形左上角的坐标就可以。
注意覆盖的规则,控制一下就可以。
然后暴力判断是否相同。
暴力回溯即可(只用回溯一个正方形区域)

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
using namespace std; const int N = 10;
const int M = 5; char s[N+5][N+5],now[N+5][N+5];
char square[M+5][M+5]; void init(){
for (int i = 0;i <3;i++)
for (int j = 0;j<5;j++)
square[i][j] = ' ';
for (int i = 0;i < 2;i++) square[i+1][0] = square[i+1][4] = '|';
for (int j = 1;j < 5;j+=2) square[0][j]=square[2][j] = '_';
} void Set(int x,int y){
for (int i = 0;i < 3;i++)
for (int j = 0;j < 5;j++){
if (i<=0 && now[i+x][j+y]!=' ' && square[i][j]==' ') continue;
now[i+x][j+y] = square[i][j];
}
for (int i = 1;i < 2;i++)
for (int j = 1;j<4;j++)
now[i+x][j+y] = ' '; } bool ok(){
for (int i = 0;i < 5;i++)
for (int j = 0;j < 9;j++)
if (now[i][j]!=s[i][j])
return false;
return true;
} void out(){
for (int i = 0;i < 5;i++){
for (int j = 0;j < 9;j++)
cout <<now[i][j];
cout << endl;
}
cout << endl; } bool dfs(int dep){
if (dep > 1 && ok()) return true;
if (dep >= 7) return false;
int temp[M+5][M+5];
for (int i = 0;i < 3;i++){
for (int j = 0;j < 5;j+=2){
for (int k = 0;k <3;k++)
for (int l = 0;l < 5;l++)
temp[k][l] = now[k+i][l+j];
Set(i,j);
if (dfs(dep+1)) return true;
for (int k = 0;k <3;k++)
for (int l = 0;l < 5;l++)
now[k+i][l+j] = temp[k][l];
}
}
return false;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
init();
int kase = 0;
while (1){
for (int i = 0;i < 5;i++){
cin.getline(s[i],15);
if (s[i][0]=='0') return 0;
}
for (int i = 0;i< 5;i++)
for (int j = 0;j < 9;j++)
now[i][j] = ' ';
if (dfs(1)){
cout <<"Case "<<++kase<<": Yes"<<endl;
}else{
cout <<"Case "<<++kase<<": No"<<endl;
}
}
return 0;
}

【习题 7-6 UVA - 12113】Overlapping Squares的更多相关文章

  1. UVA 12113 Overlapping Squares

    题意: 总共有6个2*2的正方形,判断是否能够成所给的形状. 思路: 一个正方形总共有9种摆放方式,对于整个地图来说摆放方式总共有2的9次方种摆放方式.然后将地图用9*5的数组表示,正方形的位置用其8 ...

  2. UVA - 12113 Overlapping Squares(dfs+回溯)

    题目: 给定一个4*4的棋盘和棋盘上所呈现出来的纸张边缘,问用不超过6张2*2的纸能否摆出这样的形状. 思路: dfs纸的张数,每一张中枚举这张纸左上角这个点的位置,暴力解题就可以了. 这个题的覆盖太 ...

  3. UVA - 12113 Overlapping Squares(重叠的正方形)

    题意:给定一个4*4的棋盘和棋盘上所呈现出来的纸张边缘,问用不超过6张2*2的纸能否摆出指定的形状. 分析:2*2的纸在4*4的棋盘上总共有9种放置位置,枚举所有的放置位置即可.枚举情况总共种. #p ...

  4. 【UVA】201 Squares(模拟)

    题目 题目     分析 记录一下再预处理一下.     代码 #include <bits/stdc++.h> int main() { int t=0,s,n; while(scanf ...

  5. UVA-12113 Overlapping Squares (回溯+暴力)

    题目大意:问能不能用不超过6张2x2的方纸在4x4的方格中摆出给定的图形? 题目分析:暴力枚举出P(9,6)种(最坏情况)方案即可. 代码如下: # include<iostream> # ...

  6. LA 3790 Overlapping Squares DFS

    题意: 给出一个字符矩阵,问能否是不超过6个2×2的正方形组成的. 分析: 每次找一个最表面的正方形然后DFS就好了. 一个正方形被移开后,用一个特殊符号标记上,下次再匹配的时候就直接忽略这些位置. ...

  7. ACM训练计划建议(写给本校acmer,欢迎围观和指正)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  8. Detecting diabetic retinopathy in eye images

    Detecting diabetic retinopathy in eye images The past almost four months I have been competing in a  ...

  9. ACM训练计划建议(转)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

随机推荐

  1. VS 2015支持C语言和C++程序

    先要安装C++的相关支持控件! 然后就可以使用VS编写C++或者C程序了. 默认支持的是C++,将后缀名改为C就是支持C了. 学习数据结构算法之类的,就可以通过VS来学习了. 安装 新建C++项目 C ...

  2. android CoordinatorLayout使用

    一.CoordinatorLayout有什么作用 CoordinatorLayout作为“super-powered FrameLayout”基本实现两个功能: 1.作为顶层布局 2.调度协调子布局 ...

  3. 6.控制器(ng-Controller)

    转自:https://www.cnblogs.com/best/tag/Angular/ ngController指令给视图添加一个控制器,控制器之间可以嵌套,内层控制器可以使用外层控制器的对象,但反 ...

  4. HDU 5370 Tree Maker

    一个显然的结论是,一棵n个结点的二叉树的形态数,是Catalan数第n项.

  5. Aspose.Cells相应操作及下载

    Aspose.Cells相应操作 1,上传 1.1 Workbook Workbook workBook = new Workbook(); 属性: 名称 值类型 说明 Colors Color[] ...

  6. XTUOJ 1238 Segment Tree

    Segment Tree Accepted : 3 Submit : 21Time Limit : 9000 MS Memory Limit : 65536 KB Problem Descriptio ...

  7. 解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE(转)

    问题 如下: 2017-07-16 08:50:57.436  INFO 13524 --- [           main] c.p.p.web.PointshopWebApplication   ...

  8. ArcGIS engine中Display类库 (局部刷新)

    转自原文 ArcGIS engine中Display类库 (局部刷新) Display类库包括了用于显示GIS数据的对象.除了负责实际输出图像的主要显示对象(display object)外,这个类库 ...

  9. Spark 性能相关參数配置具体解释-任务调度篇

    作者:刘旭晖 Raymond 转载请注明出处 Email:colorant at 163.com BLOG:http://blog.csdn.net/colorant/ 随着Spark的逐渐成熟完好, ...

  10. Boolean operations between triangle meshes

    Boolean operations between triangle meshes eryar@163.com Abstract. Boolean operations is one of basi ...