随便写一下的搜索,别的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(搜索)的更多相关文章

  1. BZOJ1102 [POI2007]GRZ山峰和山谷 [BFS]

    题目传送门 GRZ山峰和山谷 Description FGD小朋友特别喜欢爬山,在爬山的时候他就在研究山峰和山谷.为了能够让他对他的旅程有一个安排,他想知道山峰和山谷的数量.给定一个地图,为FGD想要 ...

  2. SQLSERVER走起微信公众帐号已经开通搜狗微信搜索

    SQLSERVER走起微信公众帐号已经开通搜狗微信搜索 请打开下面链接 http://weixin.sogou.com/gzh?openid=oIWsFt-hiIb_oYqQHaBMoNwRB2wM ...

  3. solr_架构案例【京东站内搜索】(附程序源代码)

    注意事项:首先要保证部署solr服务的Tomcat容器和检索solr服务中数据的Tomcat容器,它们的端口号不能发生冲突,否则web程序是不可能运行起来的. 一:solr服务的端口号.我这里的sol ...

  4. SQLServer地址搜索性能优化例子

    这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...

  5. HTML5轻松实现搜索框提示文字点击消失---及placeholder颜色的设置

    在做搜索框的时候无意间发现html5的input里有个placeholder属性能轻松实现提示文字点击消失功能,之前还傻傻的在用js来实现类似功能... 示例 <form action=&quo ...

  6. bzoj1079--记忆化搜索

    题目大意:有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木块涂相同色显得 ...

  7. bzoj3208--记忆化搜索

    题目大意: 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目.    我们可以把风景区看作一个n*n的地图,每个点有它的初始高度,滑雪只能从高处往低处滑[严格大于] ...

  8. Android中通过ActionBar为标题栏添加搜索以及分享视窗

    在Android3.0之后,Google对UI导航设计上进行了一系列的改革,其中有一个非常好用的新功能就是引入的ActionBar,他用于取代3.0之前的标题栏,并提供更为丰富的导航效果.Action ...

  9. 一步步开发自己的博客 .NET版(5、Lucenne.Net 和 必应站内搜索)

    前言 这次开发的博客主要功能或特点:    第一:可以兼容各终端,特别是手机端.    第二:到时会用到大量html5,炫啊.    第三:导入博客园的精华文章,并做分类.(不要封我)    第四:做 ...

随机推荐

  1. HTML中级教程 自定义列表

    在HTML初级教程中我们教授了无序列表和有序列表,很不幸,很像Peter Cushing的博士Who,自定义列表很容易被忽略.可能是因为自定义列表需要比无序列表和有序列表更多的设置和似乎更少用.当遭遇 ...

  2. 异常描述:hibernate懒加载中,用OpenSessionInViewFilter解决之后,同时对一个collection创建两个session访问导致异常(Illegal attempt to associate a collection with two open sessions)

    在保存的时候如果使用以下方法就会报错 解决:使用merge()方法就可以解决异常... merge()方法的解释: 传入的参数在数据库中不存在的时候会添加一条数据,根据主键判断已存在的时候会更新这条数 ...

  3. codeforces 665B B. Shopping(水题)

    题目链接: B. Shopping time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. codevs 1046 旅行家的预算

    传送门 1046 旅行家的预算 1999年NOIP全国联赛普及组NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold题解   题目描述 Des ...

  5. 自己实现c++中string 类

    class String { public: String(const char *str = NULL);// 普通构造函数 String(const String &other);// 拷 ...

  6. camera调试命令

    问题:adb install -r Camera.apk 2864 KB/s (7603465 bytes in 2.592s)Failure [INSTALL_FAILED_UPDATE_INCOM ...

  7. asio 中strand的作用

    namespace { // strand提供串行执行, 能够保证线程安全, 同时被post或dispatch的方法, 不会被并发的执行. // io_service不能保证线程安全 boost::a ...

  8. mfc画波形函数

    void CMyPicoTestDlg::DrawWave(CDC *pDC,CRect &rectPicture) { float fDeltaX; float fDeltaY; int n ...

  9. Flutter实战视频-移动电商-63.购物车_详细页显示购物车商品数量

    63.购物车_详细页显示购物车商品数量 购物车的图标嵌套在statck组件里面 外层套了一个stack组件 数量我们需要用Provide 返回一个container来做样式 气泡效果,中间是个数字外面 ...

  10. springboot+mongodb报错Caused by: java.net.ConnectException: Connection refused (Connection refused)

    com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.connection.SocketStrea ...