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

【题意】

在这里输入题意

【题解】

先预处理出所有的正方形(长度为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. 算法导论————KMP

    [例题传送门:caioj1177] KMP模版:子串是否出现 [题意]有两个字符串SA和SB,SA是母串,SB是子串,问子串SB是否在母串SA中出现过.如果出现过输出第一次出现的起始位置和结束位置,否 ...

  2. xml Data Type Methods in sql server

    nodes() Method (xml Data Type) https://docs.microsoft.com/en-us/sql/t-sql/xml/nodes-method-xml-data- ...

  3. legend---六、php脚本变量的生命周期是怎样的

    legend---六.php脚本变量的生命周期是怎样的 一.总结 一句话总结:应该是脚本结束变量的生命周期就完了 1.外部js找不到元素是怎么回事? 1 function myDailyTaskFin ...

  4. Spring MVC 返回视图时添加的模型数据------POJO

    POJO(Plain Old Java Objects)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称. 使用POJO名称是为了避免和 EJB混淆起来, 而且简 ...

  5. 99.重载[] * -> ->*

    #include "mainwindow.h" #include <QApplication> #include <QPushButton>> //重 ...

  6. Sqoop-1.4.6工具import和export使用详解(官网)

    不多说,直接上干货! 1.Sqoop Import (进入官网) 因为,sqoop的使用方式是: sqoop COMMAND  ARGS. 以下是  sqoop COMMAND  ARGS 以下是   ...

  7. Oracle修改表空间自增长

    下面列出详细过程: 1.通过sql plus 命令登录数据库. 在命令行下输入sqlplus “登录用户名/口令 as 登录类型”就可以登录,系统内建的用户名常用的是sys,密码是在安装oracle过 ...

  8. 分享js中 pageY = clientY + document.body.scrollTop 之间的关系

    //这里没有考虑兼容ie模式下 兼容一般主流浏览器 var $1 = document.getElementById('main') $1.onclick = function(e){ console ...

  9. C++中冒号(:)的作用

    摘于:http://blog.csdn.net/zimingjushi/article/details/6549390 (1)表示机构内位域的定义(即该变量占几个bit空间) typedef stru ...

  10. Installation from source on Windows 7 with Visual C++2012

    在这部分说明里,你将会学习到在配备有Visual C++的Windows平台下从源码安装ViSP.下面的这些安装步骤已经在32位Windows系统,CMake3.1和Visual Studio 201 ...