纯暴力就能过的,可是题目描述真心不清楚,我看了好久好久才明白题目啥意思。

为了迅速打完,代码比较冗余。

/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef long long LL;
typedef long long LL;
/*
* 输入非负整数
* 支持short、int、long、long long等类型(修改typec即可)。
* 用法typec a = get_int();返回-1表示输入结束
*/
typedef int typec;
typec get_int() {
typec res = , ch;
while (!((ch = getchar()) >= '' && ch <= '')) {
if (ch == EOF)
return -;
}
res = ch - '';
while ((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
return res;
}
//输入整数(包括负整数,故不能通过返回值判断是否输入到EOF,本函数当输入到EOF时,返回-1),用法int a = get_int2();
int get_int2() {
int res = , ch, flag = ;
while (!((ch = getchar()) >= '' && ch <= '')) {
if (ch == '-')
flag = ;
if (ch == EOF)
return -;
}
res = ch - '';
while ((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
if (flag == )
res = -res;
return res;
}
/**
* 输入一个字符串到str中,与scanf("%s", str)类似,
* 会忽略掉缓冲区中的空白字符。返回值为输入字符串
* 的长度,返回-1表示输入结束。
*/
int get_str(char *str) {
char c;
while ((c = getchar()) <= ' ') {
if(c == EOF) {
return -;
}
}
int I = ;
while (c > ' ') {
str[I++] = c; c = getchar();
}
str[I] = ;
return I;
} const int MAXN = ;
const int MAXM = ;
char graph[MAXN][MAXN];
int N, M, cnt;
int X[MAXM], Y[MAXM]; bool dfs(int x, int y) {
bool flag = false;
if (graph[x - ][y - ] == ) {
if (graph[x - ][y] == ) {
graph[x - ][y] = ;
X[cnt] = x - ;
Y[cnt] = y;
cnt++;
flag = true;
dfs(x - , y);
}
if (graph[x][y - ] == ) {
graph[x][y - ] = ;
X[cnt] = x;
Y[cnt] = y - ;
cnt++;
flag = true;
dfs(x, y - );
}
}
if (graph[x - ][y + ] == ) {
if (graph[x - ][y] == ) {
graph[x - ][y] = ;
X[cnt] = x - ;
Y[cnt] = y;
cnt++;
flag = true;
dfs(x - , y);
}
if (graph[x][y + ] == ) {
graph[x][y + ] = ;
X[cnt] = x;
Y[cnt] = y + ;
cnt++;
flag = true;
dfs(x, y + );
}
}
if (graph[x + ][y - ] == ) {
if (graph[x + ][y] == ) {
graph[x + ][y] = ;
X[cnt] = x + ;
Y[cnt] = y;
cnt++;
flag = true;
dfs(x + , y);
}
if (graph[x][y - ] == ) {
graph[x][y - ] = ;
X[cnt] = x;
Y[cnt] = y - ;
cnt++;
flag = true;
dfs(x, y - );
}
}
if (graph[x + ][y + ] == ) {
if (graph[x + ][y] == ) {
graph[x + ][y] = ;
X[cnt] = x + ;
Y[cnt] = y;
cnt++;
flag = true;
dfs(x + , y);
}
if (graph[x][y + ] == ) {
graph[x][y + ] = ;
X[cnt] = x;
Y[cnt] = y + ;
cnt++;
flag = true;
dfs(x, y + );
}
}
return flag;
} void work() {
bool change = true;
while (change) {
change = false;
for (int i = ; i < cnt; i++) {
if (dfs(X[i], Y[i])) {
change = true;
break;
}
}
}
} int main() {
int T = get_int();
int x, y;
for (int t = ; t <= T; t++) {
N = get_int();
M = get_int();
memset(graph, , sizeof(graph));
for (int i = ; i <= N + ; i++) {
graph[i][] = -;
graph[i][M + ] = -;
}
for (int j = ; j <= M; j++) {
graph[][j] = -;
graph[N + ][j] = -;
}
cnt = get_int();
for (int i = ; i < cnt; i++) {
x = X[i] = get_int();
y = Y[i] = get_int();
graph[x][y] = ;
}
work();
int ans = ;
for (int i = ; i <= N; i++) {
for (int j = ; j <= M; j++) {
if (graph[i][j] == ) {
ans++;
}
}
}
printf("Case #%d:\n%d\n", t, ans);
}
return ;
}

hdu 5254 水题的更多相关文章

  1. HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Subm ...

  2. HDU 5391 水题。

    E - 5 Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. hdu 1544 水题

    水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...

  4. HDU排序水题

    1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...

  5. hdu 2710 水题

    题意:判断一些数里有最大因子的数 水题,省赛即将临近,高效的代码风格需要养成,为了简化代码,以后可能会更多的使用宏定义,但是通常也只是快速拿下第一道水题,涨自信.大部分的代码还是普通的形式,实际上能简 ...

  6. Dijkstra算法---HDU 2544 水题(模板)

    /* 对于只会弗洛伊德的我,迪杰斯特拉有点不是很理解,后来发现这主要用于单源最短路,稍稍明白了点,不过还是很菜,这里只是用了邻接矩阵 套模板,对于邻接表暂时还,,,没做题,后续再更新.现将这题贴上,应 ...

  7. hdu 5162(水题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5162 题解:看了半天以为测试用例写错了.这题玩文字游戏.它问的是当前第i名是原数组中的第几个. #i ...

  8. hdu 3357 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...

  9. hdu 5038 水题 可是题意坑

    http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数  这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心  If not all ...

随机推荐

  1. Linux命令-mkdir

    mkdir用于创建空白文件夹 参数-p用于连续创建多层目录 参数-m用于创建自定义的目录权限 [root@localhost test]# mkdir a/b/c/d mkdir: 无法创建目录&qu ...

  2. Index & Statistics ->> Rebuild Index会不会覆盖原先Index的WITH选项设置

    昨天因为工作中遇到要对某个数据库的表通通启用data_compression,突然有个念头,就是如果我当初用"ALTER INDEX XXX ON YYY REBUILD WITH (DAT ...

  3. Maven实战(六)--- dependencies与dependencyManagement的区别

    在上一个项目中遇到一些jar包冲突的问题,之后还有很多人分不清楚dependencies与dependencyManagement的区别,本篇文章将这些区别总结下来. 1.DepencyManagem ...

  4. win8.1下解决Visual C++不兼容的方法

    1.下载visual c++的安装包 百度云下载地址为:http://pan.baidu.com/s/1c0dRAYs 2.修改MSDEV.EXE文件名 安装完成后在安装目录下找到MSDEV.EXE, ...

  5. 一个国内的 android 在线帮助网站

    只支持到 api 19 http://cs.szpt.edu.cn/android/develop/index.html

  6. 【HDOJ】1362 The Bermuda Triangle

    1. 题目描述给定几个三角形拼成一个百慕大三角形. 2. 基本思路基本思路肯定是搜索,关键点是剪枝.(1) 若存在长度为$l$的边,则一定可以拼成长度为$k \cdot l$的三角形,则可拼成长度为$ ...

  7. [HIHO1300]展胜地的鲤鱼旗(栈,dp)

    题目链接:http://hihocoder.com/problemset/problem/1300 给一个字符串,只包含'('和')',问存在多少个子串似的括号是匹配的. 匹配规则在题干中描(蒻)述( ...

  8. mac terminal 命令

    mac下显示隐藏文件 显示 defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏 defaults write com.app ...

  9. 线程——QQ邮件发送

    一.造一个QQ邮件发送的窗体 二.开始编写关于邮件发送的代码,以及当点发送按钮的时候,给发送按钮单独造了一个新的线程.这样如果发送的附件太多的话,如果不给发送按钮造新的线程,便会卡住,但是如果给发送按 ...

  10. R语言将5位数字日期转为正常日期

    R语言中用double表示日期,即从1970-1-1距离给定日期的天数,将5位数字日期转为正常日期格式的方法 as.Date(16543,origin='1970-1-1')