【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 ...
随机推荐
- spring data jpa 、hibernate、jpa之间的关系
引用:http://blog.csdn.net/u014421556/article/details/52635000 hibernate作为JPA的实现. JPA规范与ORM框架之间的关系 ...
- 01--Java IO基础
一.java.io包概览 Java IO包主要可以分为如下4类: 基于字节操作的I/O接口:InputStream和OutputStream. 基于字符操作的I/O接口:Writer和Reader 基 ...
- 【sqli-labs】 less11 POST - Error Based - Single quotes- String (基于错误的POST单引号字符型注入)
查看源码,用户名和密码通过post提交 加单引号提交 出现报错,推测对应的SQL语句 , 直接使用or构造永真登录 成功,注意此处登录的用户为表中的第一个用户 需要改变用户可以通过改变筛选条件实现 作 ...
- react-native 横向滚动的商品展示
在app中会有这种页面 像这样商品是横向的,而且要滚动,思路是利用 ScrollView 横向的滚动 思路: (a): 横向滚动的整体作为一个组件 ShopCenter {/*** 横向滚动 *** ...
- Git创建本地分支并关联远程分支(二)
创建本地分支git branch 分支名 例如:git branch dev,这条命令是基于当前分支创建的本地分支,假设当前分支是master(远程分支),则是基于master分支创建的本地分支dev ...
- 深度遍历DFS
目录: https://zhipianxuan.github.io/ 一.树的DFS 二.二维矩阵的DFS 三.图的DFS 一.题目一:二维矩阵(输出所有路径数) 思路:从起点开始,DFS,直到走到终 ...
- HDU 4405 Aeroplane chess(概率dp,数学期望)
题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...
- C#第八节课
for的穷举迭代.while.do while using System;using System.Collections.Generic;using System.Linq;using Syste ...
- tornado服务器运行django应用
在jumpserver项目中看到的 def main(): from django.core.wsgi import get_wsgi_application import tornado.wsgi ...
- BZOJ 3218 UOJ #77 A+B Problem (主席树、最小割)
大名鼎鼎的A+B Problem, 主席树优化最小割-- 调题死活调不对,一怒之下改了一种写法交上去A了,但是改写法之后第4,5个点常数变大很多,于是喜提UOJ全站倒数第三 目前还不知道原来的写法为什 ...