【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 ...
随机推荐
- MemcachedClient 使用说明
上一篇介绍了Memcached基本使用方法<Memcached使用手册>,下面介绍java如何操作memcached.使用的是java_memcached-release_2.6.6. 一 ...
- 前端性能优化---DOM操作
小结 1缓存DOM对象 场景:缓存DOM对象的方式也经常被用在元素的查找中,查找元素应该是DOM操作中最频繁的操作了,其效率优化也是大头.在一般情况下,我们会根据需要,将一些频繁被查找的元素缓存起来, ...
- Gradle 自定义Task 打Jar包
可以作为Jar包内容的有两个地方: : build/intermediates/bundles/release/ 下的classes.jar : build/intermediates/classes ...
- mysql自动添加时间的方法
时间添加方法,可以在编辑数据时方便时间选择输入: 将时间列DataType设为timestamp,设定其默认值为CURRENT_TIMESTAMP. 这样每次插入一条新纪录,数据库会自动在时间段存储当 ...
- hibernate_04_hbm.xml介绍
先贴上类文件Students.hbm.xml <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC & ...
- .NET Framework 3.5 安装
今天vCenter服务器悲剧了,只好火速重新部署新vCenter服务器... Windows server 2016 中,安装VCenter 5.5 提示 未安装 .NET Framework 3. ...
- 【转】上拉下拉电阻、I/O输出(开漏、推挽等)
作者:BakerZhang 链接:https://www.jianshu.com/p/3ac3a29b0f58来源:简书 感谢! ——————————————————————————————————— ...
- HTML 1.1页面js修改文字颜色
昨天的报告页面,想要实现根据不同文字内容改变字体颜色,效果图: 调试了半天出不来效果,最后请教了前端,上代码: <!DOCTYPE html> <html lang="en ...
- codeforces 466B Wonder Room(思维,暴力)
题目 参考了别人的博客,百度来的博客 #include<iostream> #include<string> #include<stdio.h> #include& ...
- SQL第一节课
phpmyadmin create table 表名( 列名 数据类型 是否为空 (是否主键|是否唯一|外键关系), 列名 数据类型...(最后一列不加逗号)) create database 数据库 ...