【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 ...
随机推荐
- Django学习案例一(blog):四. 使用Admin
1. 创建超级用户 python manage.py createsuperuser 创建过程中输入用户名,并设定密码(记住). 后台管理汉化.修改settings.py中LANGUAGE_CODE ...
- PythonOpenCV:MLP用于最近邻搜索
一:简单C++版本的链接: http://blog.csdn.net/kaka20080622/article/details/9039749 OpenCV的ml模块实现了人工神经网络(Artific ...
- OpenCV边缘检测的详细参数调节
1. findCountours 转载于http://blog.sina.com.cn/s/blog_7155fb1a0101a90h.html findContours函数,这个函数的原型为: &l ...
- 【sqli-labs】 less25 GET- Error based -All you OR&AND belong to us -string single quote(GET型基于错误的去除了or和and的单引号注入)
加单引号 order by一下 http://localhost/sqli-labs-master/Less-25/?id=1' order by 1%23 order by 变成了der by 下面 ...
- 【sqli-labs】 less17 POST - Update Query- Error Based - String (基于错误的更新查询POST注入)
这是一个重置密码界面,查看源码可以看到username作了防注入处理 逻辑是先通过用户名查出数据,在进行密码的update操作 所以要先知道用户名,实际情况中可以注册用户然后实行攻击,这里先用admi ...
- raspberry pi树莓派设置
买了个pi3b 安装系统 需要class10 TF卡.读卡器 下载系统并解压Raspbianhttps://www.raspberrypi.org/downloads/raspbian/访问慢的话请用 ...
- day35-2 类的三大特性---多态,以及菱形继承问题
目录 菱形继承问题 经典类 新式类 菱形继承 大招 多态与多态性 多态 多态性 多态在Python中的体现 鸭子类型(重要) 结论 菱形继承问题 经典类 没有继承object类的就是经典类,只有Pyt ...
- 玩转python 各种数据类型的转换
# -*- coding: utf-8 -*- # @Time : 2019/4/28 14:27 # @Author : wujf # @Email : 1028540310@qq.com # @F ...
- Python笔记(29)----进程
目录: 一.进程 多任务的概念 创建子进程----fork[Linux] 全局变量在多个进程中不共享 多次fork() 创建进程----multiprocessing[windows] 二.线程 一. ...
- dmidecode输出详解
一.先来看几个用dmidecode查看内存信息的例子. 1.查看内存槽数.那个槽位插了内存,大小是多少 [root@jiangyi01.sqa.zmf /home/ahao.mah] #dmideco ...