【POJ 1084】 Square Destroyer
【题目链接】
http://poj.org/problem?id=1084
【算法】
迭代加深
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std; int i,n,T,step,k,x;
bool dest[]; inline bool is_square(int x,int y,int len)
{
int i,l,r;
bool ret = true;
l = (x - ) * ( * n + ) + y;
r = l + len - ;
for (i = l; i <= r; i++) ret &= (dest[i] ^ );
l = (x + len - ) * ( * n + ) + y;
r = l + len - ;
for (i = l; i <= r; i++) ret &= (dest[i] ^ );
l = n * x + (x - ) * (n + ) + y;
r = n * (x + len - ) + (x + len - ) * (n + ) + y;
for (i = l; i <= r; i += * n + ) ret &= (dest[i] ^ );
l = n * x + (x - ) * (n + ) + y + len;
r = n * (x + len - ) + (x + len - ) * (n + ) + y + len;
for (i = l; i <= r; i += * n + ) ret &= (dest[i] ^ );
return ret;
}
inline bool check()
{
int i,j,k;
for (k = ; k <= n; k++)
{
for (i = ; i <= n - k + ; i++)
{
for (j = ; j <= n - k + ; j++)
{
if (is_square(i,j,k))
return false;
}
}
}
return true;
}
inline bool IDDFS(int dep)
{
int i,j,k,x,y,len,l,r;
if (dep > step)
{
if (check())
return true;
else return false;
}
x = y = len = ;
for (k = ; k <= n; k++)
{
for (i = ; i <= n - k + ; i++)
{
for (j = ; j <= n - k + ; j++)
{
if (is_square(i,j,k))
{
x = i;
y = j;
len = k;
break;
}
}
if (x) break;
}
if (x) break;
}
l = (x - ) * ( * n + ) + y;
r = l + len - ;
for (i = l; i <= r; i++)
{
dest[i] = true;
if (IDDFS(dep+))
return true;
dest[i] = false;
}
l = (x + len - ) * ( * n + ) + y;
r = l + len - ;
for (i = l; i <= r; i++)
{
dest[i] = true;
if (IDDFS(dep+))
return true;
dest[i] = false;
}
l = n * x + (x - ) * (n + ) + y;
r = n * (x + len - ) + (x + len - ) * (n + ) + y;
for (i = l; i <= r; i += * n + )
{
dest[i] = true;
if (IDDFS(dep+))
return true;
dest[i] = false;
}
l = n * x + (x - ) * (n + ) + y + len;
r = n * (x + len - ) + (x + len - ) * (n + ) + y + len;
for (i = l; i <= r; i += * n + )
{
dest[i] = true;
if (IDDFS(dep+))
return true;
dest[i] = false;
}
return false;
} int main()
{ scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (i = ; i <= * n * (n + ); i++) dest[i] = false;
scanf("%d",&k);
for (i = ; i <= k; i++)
{
scanf("%d",&x);
dest[x] = true;
}
for (i = ; i <= * n * (n + ); i++)
{
step = i;
if (IDDFS())
break;
}
printf("%d\n",step);
} return ; }
【POJ 1084】 Square Destroyer的更多相关文章
- 【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)
[POJ 2942]Knights of the Round Table(双联通分量+染色判奇环) Time Limit: 7000MS Memory Limit: 65536K Total Su ...
- 【POJ 2195】 Going Home(KM算法求最小权匹配)
[POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
随机推荐
- 浅谈html运行原理
浅谈HTML运行原理,所谓的HTML简单的来说就是一个网页,虽然第一节就讲html原理可能大家会听不懂,就当是给一个初步印象把,至少大概知道一个网页的运行流程是怎样的,下面上一张图: 大致的一个htm ...
- 努比亚 Z17(Nubia NX563J) 解锁BootLoader 并刷入recovery
工具下载链接:https://pan.baidu.com/s/1mjEzcyG 备用下载链接:https://pan.baidu.com/s/1eTdx6Zg 密码:1d3r 本篇教程教你如何傻瓜式解 ...
- 【PostgreSQL-9.6.3】函数(1)--数值型函数
函数表示对输入参数返回一个特殊计算结果的值.PostgreSQL中的函数种类比较丰富,主要分为以下几类:数值型函数.字符型函数.日期和时间函数.条件判断函数.系统函数.加密函数以及其他函数.这篇文章只 ...
- Content-Encoding值
Content-Encoding值 gzip 表明实体采用GNU zip编码 compress 表明实体采用Unix的文件压缩程序 deflate 表明实体是用zlib的格式压缩的 identity ...
- 浅谈Web缓存-缓存的实现过程详解
在前端开发中,性能一直都是被大家所重视的一点,然而判断一个网站的性能最直观的就是看网页打开的速度.其中提高网页反应速度的一个方式就是使用缓存.一个优秀的缓存策略可以缩短网页请求资源的距离,减少延迟,并 ...
- 【转】在VMware中为Linux系统安装VM-Tools的详解教程
在VMware中为Linux系统安装VM-Tools的详解教程 如果大家打算在VMware虚拟机中安装Linux的话,那么在完成Linux的安装后,如果没有安装Vm-Tools的话,一部分功能将得不到 ...
- Python统计字符串中出现次数最多的人名
人名最多数统计题目摘自https://python123.io 描述编程模板中给出了一个字符串,其中包含了含有重复的人名,请直接输出出现最多的人名. ...
- BPM结束任务
var pi = tw.system.findProcessInstanceByID("158");for(var i=0; i<pi.tasks.length; i++) ...
- TCP中的RST标志(Reset)详解
在谈RST攻击前,必须先了解TCP:如何通过三次握手建立TCP连接.四次握手怎样把全双工的连接关闭掉.滑动窗口是怎么传输数据的.TCP的flag标志位里RST在哪些情况下出现.下面我会画一些尽量简化的 ...
- PAT_A1119 Pre- and Post-order Traversals
Source: PAT A1119 Pre- and Post-order Traversals (30 分) Description: Suppose that all the keys in a ...