BZOJ1102(搜索)
随便写一下的搜索,别的OJ深搜就过了,强大的BZOJ成功栈溢出RE了我并使我屈服地用广搜过掉,第一行手动开栈惨遭无视。
广搜:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <fstream>
#include <bitset>
#define init(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define irep(i, a, b) for (int i = a; i >= b; i--)
using namespace std; typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18; template <typename T> void read(T &x) {
x = ;
int s = , c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') s = -;
for (; isdigit(c); c = getchar())
x = x * + c - ;
x *= s;
} template <typename T> void write(T x) {
if (x < ) x = -x, putchar('-');
if (x > ) write(x / );
putchar(x % + '');
} template <typename T> void writeln(T x) {
write(x);
puts("");
} const int maxn = 1e3 + ;
int n, A[maxn][maxn], up, down;
bool vis[maxn][maxn]; int bfs(int x, int y) {
queue<P> Q;
Q.push(P(x, y));
vis[x][y] = true;
bool small = true, equal = true, large = true;
while (!Q.empty()) {
int i = Q.front().first, j = Q.front().second;
Q.pop();
rep(a, -, ) rep(b, -, ) {
int nx = i + a, ny = j + b;
if (nx < || nx > n || ny < || ny > n) continue; int val = A[nx][ny], k = -;
if (val == A[i][j]) {
if (vis[nx][ny]) continue;
Q.push(P(nx, ny));
vis[nx][ny] = true;
} else if (val > A[i][j]) {
k = ;
} else k = ; if (k == ) small = false, equal = false;
else if (k == ) large = false, equal = false;
}
}
if (equal) return ;
if (small) return ;
if (large) return ;
return -;
} int main() {
read(n);
rep(i, , n) rep(j, , n) read(A[i][j]);
rep(i, , n) rep(j, , n) {
if (!vis[i][j]) {
int k = bfs(i, j);
if (k == ) {
up++, down++;
} else if (k == ) {
up++;
} else if (k == ) {
down++;
}
}
}
printf("%d %d\n", up, down);
return ;
}
深搜:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <fstream>
#include <bitset>
#define init(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define irep(i, a, b) for (int i = a; i >= b; i--)
using namespace std; typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18; template <typename T> void read(T &x) {
x = ;
int s = , c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') s = -;
for (; isdigit(c); c = getchar())
x = x * + c - ;
x *= s;
} template <typename T> void write(T x) {
if (x < ) x = -x, putchar('-');
if (x > ) write(x / );
putchar(x % + '');
} template <typename T> void writeln(T x) {
write(x);
puts("");
} const int maxn = 1e3 + ;
int n, A[maxn][maxn], up, down;
bool vis[maxn][maxn]; int dfs(int i, int j) {
vis[i][j] = true;
bool small = true, equal = true, large = true;
rep(a, -, ) rep(b, -, ) {
int nx = i + a, ny = j + b;
if (nx < || nx > n || ny < || ny > n) continue; int val = A[nx][ny], k = -;
if (val == A[i][j]) {
if (vis[nx][ny]) continue;
k = dfs(nx, ny);
} else if (val > A[i][j]) {
k = ;
} else k = ; if (k == ) small = false, equal = false;
else if (k == ) large = false, equal = false;
else if (k == ) small = false, large = false;
else small = false, equal = false, large = false;
}
if (equal) return ;
if (small) return ;
if (large) return ;
return -;
} int main() {
read(n);
rep(i, , n) rep(j, , n) read(A[i][j]);
rep(i, , n) rep(j, , n) {
if (!vis[i][j]) {
int k = dfs(i, j);
if (k == ) {
up++, down++;
} else if (k == ) {
up++;
} else if (k == ) {
down++;
}
}
}
printf("%d %d\n", up, down);
return ;
}
BZOJ1102(搜索)的更多相关文章
- BZOJ1102 [POI2007]GRZ山峰和山谷 [BFS]
题目传送门 GRZ山峰和山谷 Description FGD小朋友特别喜欢爬山,在爬山的时候他就在研究山峰和山谷.为了能够让他对他的旅程有一个安排,他想知道山峰和山谷的数量.给定一个地图,为FGD想要 ...
- SQLSERVER走起微信公众帐号已经开通搜狗微信搜索
SQLSERVER走起微信公众帐号已经开通搜狗微信搜索 请打开下面链接 http://weixin.sogou.com/gzh?openid=oIWsFt-hiIb_oYqQHaBMoNwRB2wM ...
- solr_架构案例【京东站内搜索】(附程序源代码)
注意事项:首先要保证部署solr服务的Tomcat容器和检索solr服务中数据的Tomcat容器,它们的端口号不能发生冲突,否则web程序是不可能运行起来的. 一:solr服务的端口号.我这里的sol ...
- SQLServer地址搜索性能优化例子
这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...
- HTML5轻松实现搜索框提示文字点击消失---及placeholder颜色的设置
在做搜索框的时候无意间发现html5的input里有个placeholder属性能轻松实现提示文字点击消失功能,之前还傻傻的在用js来实现类似功能... 示例 <form action=&quo ...
- bzoj1079--记忆化搜索
题目大意:有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木块涂相同色显得 ...
- bzoj3208--记忆化搜索
题目大意: 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目. 我们可以把风景区看作一个n*n的地图,每个点有它的初始高度,滑雪只能从高处往低处滑[严格大于] ...
- Android中通过ActionBar为标题栏添加搜索以及分享视窗
在Android3.0之后,Google对UI导航设计上进行了一系列的改革,其中有一个非常好用的新功能就是引入的ActionBar,他用于取代3.0之前的标题栏,并提供更为丰富的导航效果.Action ...
- 一步步开发自己的博客 .NET版(5、Lucenne.Net 和 必应站内搜索)
前言 这次开发的博客主要功能或特点: 第一:可以兼容各终端,特别是手机端. 第二:到时会用到大量html5,炫啊. 第三:导入博客园的精华文章,并做分类.(不要封我) 第四:做 ...
随机推荐
- HDU1102 Constructing Roads —— 最小生成树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 题解: 纯最小生成树,只是有些边已经确定了要加入生成树中,特殊处理一下这些边就可以了. krus ...
- 什么是HTTP协议?
HTTP协议(超文本传输协议)位于TCP/IP协议栈的应用层.传输层采用面向连接的TCP HTTP请求详细过程
- hdu-5596 GTW likes gt(模拟+优先队列)
题目链接: GTW likes gt Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- hdu-5667 Sequence(矩阵快速幂+费马小定理+快速幂)
题目链接: Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- SDOI2017 Round1 Day2 题解
T2好厉害啊……AK不了啦……不过要是SCOI考这套题就好了240保底. BZOJ4819 新生舞会 模板题,分数规划+二分图最大权匹配. 费用流跑得过,可以不用KM. UPD:分数规划用迭代跑得飞快 ...
- SSL卸载技术对于HTTPS应用的优化与思考
迅猛发展的互联网为我们提供了丰富的信息资源,在带来便利的同时也影响着人们工作和生活方式.而让我们无法忽视的是,在开放的互联网所带来的繁荣背后,同时也潜藏着安全方面的隐患.随着人们对网络的依赖愈渐加深, ...
- bzoj4521
数位dp 复习数位dp 数位dp一般用记忆化搜索来解决 观察需要满足的条件,然后计入状态 状态还要记录是否达到上线,以及前导零 比如说这道题 dfs(bit,a4,a8,cnt,last,limit) ...
- 3.sql中的向上递归和向下递归
1.向下递归 select * from table_name where 条件 connect by prior bmbm(本级关联条件)=sjbmbm(上级关联条件) start with bmb ...
- SQL Server 盛宴系列 webcast
数据库学习站点,示例,视频 http://technet.microsoft.com/zh-cn/dd722671.aspx
- 转 vs2008使用技巧推荐
Visual Studio 2008自带的1000多个 Windows 系统使用的各种图标.光标和动画文件在Visual Studio 2008的安装目录下,\Microsoft Visual Stu ...