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

【题意】

在这里输入题意

【题解】

先预处理出所有的正方形(长度为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. @Not - Empty-Null-Blank

    1 @NotEmpty :不能为null,且Size>0 2  @NotNull:不能为null,但可以为empty,没有Size的约束 3  @NotBlank:只用于String,不能为nu ...

  2. 关于Javascript的forEach 和 map

    本篇博客转载自 https://blog.fundebug.com/2018/02/05/map_vs_foreach/ 如果你已经有使用JavaScript的经验,你可能已经知道这两个看似相同的方法 ...

  3. I want to do——输入流readline阻塞问题

    据悉,外界对程序员的印象不是木讷就是死板,不是最笨就是不爱说话,不是宅就是闷骚.昨天我们老左批评我说,自从你写了程序了,你以前的优点都退化了.放在去年,我还觉得我没什么啊,程序员就是这样啊,那是因为我 ...

  4. Node书签

    1.开源项目 [译]过去一年25个惊人的开源Node.js项目(2018版) 百度网盘下载助手

  5. ES6学习笔记(二)变量的解构与赋值

    1.数组的解构赋值 1.1基本用法 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前,为变量赋值,只能直接指定值. let a = 1 ...

  6. selenium+python 安装使用

    一.序言 selenium官网selenium简单教程selenium完整教程python基础教程 二.安装python3 https://www.python.org/downloads/relea ...

  7. 实现人脸识别性别之路---try语句的使用

    Try语句 用法:处理异常信息 存在的形式:try-except X-except T...-except-else-finally(其中X T为错误的类型) 表达意思:try语句是执行正常语句,如果 ...

  8. Swift学习笔记(3)--基本运算符

    基本运行符: +(加法.正数) - (减法.负数) *  (乘法) / (除法) % (求余)  : 在Swift中,求余可以是浮点数求余. &&(逻辑与) || (逻辑或) ^ (逻 ...

  9. HRBUST 1376 能量项链

    能量项链 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HRBUST. Original ID: 13 ...

  10. 自写的开发框架,胜于官方的clientAPP的实战开发。(已开源)

    已开源,欢迎大家fork 小弟github地址为https://github.com/10045125/vanda 好久没写博客了,这段时间主要是要做的事情太多.如今接触android有段时间了.非常 ...