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

【题意】

在这里输入题意

【题解】

先预处理出所有的正方形(长度为1,2...n的)所包含哪些边。
然后记录每个正方形的应有边长和实际边长(有些边被删掉了);
然后搜的时候,每次找到第一个还是完整的正方形。
枚举删掉它的哪一条边。
然后看看哪些正方形会受到影响。
修改那些受影响的正方形的实际边长。
然后进入下一层。继续搜。
然后回溯影响。
直到所有的正方形都变成不完整的就可以了。
暴力就好。不用加优化。

【代码】

/*
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 = 150; int T,n,cnt[N],tot,fullsize[N],realsize[N],ans,totm;
bool contain[N][N]; int GetColumn(int x,int y){
int temp1 = (x-1)*(n+1) + x*n + y;
return temp1;
} int GetRow(int x,int y){
int temp1 = (x-1)*(n+1) + (x-1)*n +y;
return temp1;
} int findfirst(){
for (int i = 1;i <= tot;i++)
if (fullsize[i]==realsize[i]) return i;
return -1;
} void dfs(int dep){
if (dep >= ans) return;
int idx = findfirst();
if (idx==-1){
ans = dep;
return;
} for (int i = 1;i <= totm;i++)
if (cnt[i] == 1 && contain[idx][i]){
cnt[i] = 0;
for (int j = 1;j <= tot;j++) if (contain[j][i]) realsize[j]--; dfs(dep+1); cnt[i] = 1;
for (int j = 1;j <= tot;j++) if (contain[j][i]) realsize[j]++;
}
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> T;
while (T--){
tot = 0;
memset(contain,0,sizeof contain);
memset(fullsize,0,sizeof fullsize);
memset(realsize,0,sizeof realsize); cin >>n;
totm = 2*n*(n+1);
for (int i = 1;i <= totm;i++) cnt[i] = 1; int k;cin >> k;
while(k--){
int x;cin >>x;cnt[x] = 0;
}
for (int len = 1;len <= n;len++){
for (int i = 1;i <= n-len+1;i++){
for (int j = 1;j <= n - len+1;j++){
//(i,j)
tot++;
int x;
fullsize[tot] = len*4;
for (int k = 0;k < len;k++){ x = GetColumn(i+k,j);
contain[tot][x] = 1;
realsize[tot]+=cnt[x]; x = GetColumn(i+k,j+len);
contain[tot][x] = 1;
realsize[tot]+=cnt[x]; x = GetRow(i,j+k);
contain[tot][x] = 1;
realsize[tot]+=cnt[x]; x = GetRow(i+len,j+k);
contain[tot][x] = 1;
realsize[tot]+=cnt[x];
}
}
}
} ans = 1000;
dfs(0);
cout << ans << endl;
}
return 0;
}

【例7-15 UVA-1603】Square Destroyer的更多相关文章

  1. UVA 1603 Square Destroyer

    题意: 给定一个火柴棒拼成的方格阵,然后去掉一些火柴棒,问至少再去掉几根火柴棒能够让图中一个正方形都没有. 思路: 1. 由于题目中给定了 n 的范围,2 * n * (n + 1) <= 60 ...

  2. UVA - 1603 Square Destroyer (DLX可重复覆盖+IDA*)

    题目链接 给你一个n*n的由火柴组成的正方形网格,从中预先拿掉一些火柴,问至少还需要拿掉多少火柴才能破坏掉所有的正方形. 看到这道题,我第一反应就是——把每根火柴和它能破坏掉的正方形连边,不就是个裸的 ...

  3. UVA 11542 - Square(高斯消元)

    UVA 11542 - Square 题目链接 题意:给定一些数字.保证这些数字质因子不会超过500,求这些数字中选出几个,乘积为全然平方数,问有几种选法 思路:对每一个数字分解成质因子后.发现假设要 ...

  4. xor方程组消元 UVA 11542 Square

    题目传送门 题意:给n个数,选择一些数字乘积为平方数的选择方案数.训练指南题目. 分析:每一个数字分解质因数.比如4, 6, 10, 15,, , , , 令,表示选择第i个数字,那么,如果p是平方数 ...

  5. (中等) POJ 1084 Square Destroyer , DLX+可重复覆盖。

    Description The left figure below shows a complete 3*3 grid made with 2*(3*4) (=24) matchsticks. The ...

  6. UVa 11461 - Square Numbers【数学,暴力】

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  7. UVa 11542 Square (高斯消元)

    题意:给定 n 个数,从中选出一个,或者是多个,使得选出的整数的乘积是完全平方数,求一共有多少种选法,整数的素因子不大于 500. 析:从题目素因子不超过 500,就知道要把每个数进行分解.因为结果要 ...

  8. 7-15 Square Destroyer 破坏正方形 uva1603

    先是处理所有的正方形 从边长为1开始 将其边存好 满边存好 然后不断扫描正方形  并且进行拆除  直到拆完或者 步数小于等于9(启发方程  因为n小于等于5  九次足以将所有的拆完) 代码实施有很多细 ...

  9. UVA 11461 - Square Numbers 数学水题

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

随机推荐

  1. 网易2016研发project师笔试题

    网易2016研发project师笔试题 2015/12/9 11:25(网上收集整理的,參考答案在后面,若有错误请大神指出) 1. 运行指令find / -name "test.c" ...

  2. Python数据可视化——散点图

    PS: 翻了翻草稿箱. 发现竟然存了一篇去年2月的文章...尽管naive.还是发出来吧... 本文记录了python中的数据可视化--散点图scatter, 令x作为数据(50个点,每一个30维), ...

  3. 团队作业——团队项目Alpha版本发布

    该作业所属课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 作业要求链接    https://edu.cnblogs. ...

  4. 分享《Python 游戏编程快速上手(第3版)》高清中文版PDF+高清英文版PDF+源代码

    通过编写一个个小巧.有趣的游戏来学习Python,通过实例来解释编程的原理的方式.14个游戏程序和示例,介绍了Python基础知识.数据类型.函数.流程控制.程序调试.流程图设计.字符串操作.列表和字 ...

  5. Vue2.0八——知识点整理

    1.active-class是哪个组件的属性?嵌套路由怎么定义? 答:vue-router模块的router-link组件. 2.怎么定义vue-router的动态路由?怎么获取传过来的动态参数? 答 ...

  6. 【Uva 1631】Locker

    [Link]: [Description] 有一个n(n≤1000)位密码锁,每位都是0-9,可以循环旋转.每次可以让1-3个相邻 数字同时往上或者往下转一格.例如,567890->567901 ...

  7. 漫漫人生路,学点Jakarta基础-Java8函数式编程

    接口默认方法 Java8版本以后新增了接口的默认方法,不仅仅只能包含抽象方法,接口也可以包含若干个实例方法.在接口内定义实例方法(但是注意需要使用default关键字) 在此定义的方法并非抽象方法,而 ...

  8. IIS7下设置AD单点登录

    简介:IIS7下设置AD单点登录 1.选中网站,双击“身份验证”: 2.启用“Window身份验证”.禁用“匿名身份验证”.启用“基本身份验证”: 3.在“基本身份验证”上面点右键,选择“编辑”,输入 ...

  9. Spark Tachyon实战应用(配置启动环境、运行spark和运行mapreduce)

    Tachyon实战应用 配置及启动环境 修改spark-env.sh 启动HDFS 启动Tachyon Tachyon上运行Spark 添加core-site.xml 启动Spark集群 读取文件并保 ...

  10. ElasticSearch、Kibana Web管理

    ElasticSearch的Web管理 http://localhost:9200/ http://localhost:9200/cluster/health?pretty http://localh ...