随便写一下的搜索,别的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 ;
}

最新文章

  1. Intellij Idea中定制getter setter的模板
  2. Y+的一些讨论
  3. EditorGUILayout.EnumPopup 枚举弹出选择菜单
  4. Unique Paths | &amp; ||
  5. UltraEdit 列模式
  6. 关于egit的日常操作总结
  7. 万网免费主机wordpress快速建站教程-wordpress下载及安装
  8. VB 增强的部件与引用
  9. Python快速入门(5)
  10. AndroidTv开发中常用的adb命令
  11. @Scheduled不执行的原因
  12. HashTable和HashMap的区别详解(转)
  13. 插件 DataTable 创建列表 render参数的详解与如何传递本行数据id
  14. 【linux】ubuntu下crontab无效解决方法
  15. 如何在Angular优雅编写HTTP请求
  16. ODAC(V9.5.15) 学习笔记(九)TOraSQLMonitor
  17. Java自动装箱中的缓存原理
  18. 安装postgresql之后为什么找不到postgresql service
  19. PHP扩展--XHProf优化PHP程序
  20. iOS开发API常用英语名词

热门文章

  1. 激活win10企业长期服务版
  2. 卡特兰数 HDU2067 &amp; HDU4165 &amp; HDU1134
  3. Gym - 100187A A - Potion of Immortality —— 贪心
  4. 步入C编程的第一天
  5. PL/SQL DEVELOPER执行计划的查看
  6. jQuery ajax序列化函数
  7. 并不对劲的CTS2019
  8. vue中的 v-if VS v-show
  9. bzoj 3992 [SDOI2015] 序列统计 —— NTT (循环卷积+快速幂)
  10. 微信小程序的ajax数据请求wx.request