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

【题意】

在这里输入题意

【题解】

先预处理出所有的正方形(长度为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. Ubuntu系统下的Mysql安装与使用

    摘要 在本篇博文中.笔者将从基础出发.介绍Mysql在Linux环境下的安装和基本使用命令,仅适用于Mysql刚開始学习的人.大牛请绕道-- 安装Mysql数据库 这里介绍最最简单的安装方式,至于编译 ...

  2. BZOJ2895: 球队预算

    [传送门:BZOJ2895] 简要题意: 在一个篮球联赛里,有n支球队,球队的支出是和他们的胜负场次有关系的,具体来说,第i支球队的赛季总支出是Ci*x^2+Di*y^2,Di<=Ci.(赢得多 ...

  3. Lesson 1 Basic Concepts: Part 2

    Getting your web site ‘live’ on the Web With the nerd background details under our belts, we can now ...

  4. css3中rem和em是干嘛的

    css3中rem和em是干嘛的 一.总结 一句话总结:对rem综合评价是用来做web app它绝对是最合适的人选之一. 这里我特别强调web app,web page就不能使用rem吗,其实也当然可以 ...

  5. FZU 1968 Twinkling lights III

    Twinkling lights III Time Limit: 8000ms Memory Limit: 131072KB This problem will be judged on FZU. O ...

  6. 洛谷 P2309 loidc,卖卖萌

    P2309 loidc,卖卖萌 题目背景 Loidc萌萌哒. 他最近一直在靠卖萌追求他的真爱——vivym,经过几轮攻势后vivym酱眼看就要被他所攻略.擅长数据结构的vivym决定利用强大的数据结构 ...

  7. [Python] Generates permutations

    >>> import itertools >>> for p in itertools.permutations('ABCD'): ... print(p) ('A ...

  8. [BZOJ4184]shallot 线段树+线性基

    链接 题意:给你每个数字出现的时间和消失的时间,求每个时刻最大异或和 题解 按照时间建立线段树,线段树每个节点开个vector存一下这个时间区间有哪些数,然后递归进入的时候加入线性基,开一个栈记录一下 ...

  9. 调用google翻译

    1. [代码]maven依赖     ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <dependency>     <groupId>org.a ...

  10. deep-in-es6(一)

    一 迭代器和for-of循环 以前的一些遍历数组: function c(n) { console.log(n); } 方法一: for(let i = 0;i < arr.length;i++ ...