【题目链接】

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的更多相关文章

  1. 【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)

    [POJ 2942]Knights of the Round Table(双联通分量+染色判奇环) Time Limit: 7000MS   Memory Limit: 65536K Total Su ...

  2. 【POJ 2195】 Going Home(KM算法求最小权匹配)

    [POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  3. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  4. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  5. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  6. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  7. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  8. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  9. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

随机推荐

  1. RRDtool入门详解

    ---------------原创内容,转载请注明出处.<yaoyao0777@Gmail.com>------------ 一.概述 RRDtool(round-robin databa ...

  2. ★Java语法(七)——————————循环语句

    package 自我总结; public class 循环语句 { public static void main(String[] args) { // while 循环 // 用法: // whi ...

  3. HDFS 处理命令记录

    hdfs dfs -ls hdfs dfs -mkdir hdfs dfs -put hdfs dfs -get hdfs dfs -cat hadoop 执行jar  输出的目录 必须要不存在的 y ...

  4. Apex语言(四)选择(决策)结构

    1.选择结构 选择结构是当满足某个条件或不满足某个条件时,需要进行决策以控制执行的流程. 2.if语句 if语句由布尔表达式后跟一个或多个语句组成. [格式] if(条件表达式){ 语句: } [流程 ...

  5. nyoj24-素数 距离问题

    素数距离问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 现在给出你一些数,要求你写出一个程序,输出这些整数相邻最近的素数,并输出其相距长度.如果左右有等距离长度素数 ...

  6. 那么再会吧!OI!(HNOI2019退役记)

    现在是4月7号7点. 退役了. 至此,整个LSOI17届全部毕业. 想说些什么呢?不知道啊. day1紧张过头,真正开始了解题意是在11点以后.半路忘了kmp怎么打,第一题计算几何根本没管,好啊,第三 ...

  7. 什么是hashMap,初始长度,高并发死锁,java8 hashMap做的性能提升

    问题1:HashM安排的初始长度,为什么? 初始长度是 16,每次扩展或者是手动初始化,长度必须是 2的幂. 因为: index = HashCode(Key) & (length - 1), ...

  8. HRBUST 1214 方格取数

    方格取数 Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged on HRBUST. Original ID: 12 ...

  9. poj 1523 求割点把一个图分成几个联通部分

    #include<stdio.h> #include<string.h> #define N 1100 struct node { int u,v,next; }bian[N* ...

  10. cogs 983. [NOIP2003] 数字游戏

    983. [NOIP2003] 数字游戏 ★☆   输入文件:numgame.in   输出文件:numgame.out   简单对比时间限制:1 s   内存限制:128 MB 题目描述 丁丁最近沉 ...