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

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

/*
* 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. BS与CS的比较

    http://www.oschina.net/news/57811/open-web-not-died?p=2#comments 浏览器是为浏览文档设计的,它的界面布局其实只有从上至下的流布局一种,浏 ...

  2. VCL设计方法概论(自己总结了9条),以及10个值得研究的控件 good

    VCL设计方法概论 1. 把Delphi对象改造成一个Windows窗口,主要是要设置Handle和回调函数.在创建一个Windows窗口后,将其句柄赋值给Delphi对象的属性,这个并不难,相当于从 ...

  3. Fiddler如何抓取使用了SSL或TLS传输的Android App流量

    上篇文章介绍了Burpsuite如何抓取使用了SSL或TLS传输的Android App流量, 那么使用Fiddler的时候其实 也会出现与burpsuite同样的情况,解决方案同样是需要将Fiddl ...

  4. Android EditText获取光标位置并插入字符删除字符

    1.获取光标位置 int index = editText.getSelectionStart(); 2.在光标处插入字符 int index = editText.getSelectionStart ...

  5. html 用图片代替重置按钮

    提交时,若把按钮设置成图片提交特别方便只要 <input type="image" alt="点此提交" src="images/button. ...

  6. Javascript学习-闭包

    看的这篇 http://www.ruanyifeng.com/blog/2009/08/learning_javascript_closures.html 各种专业文献上的"闭包" ...

  7. Python3 学习第十二弹: 补充something

    python中遇到 *keys, **keys的形式 其实 * 代表传递任意个无名字参数,这些参数通过Tuple访问 >>> def sum(*keys): ret= 0 for i ...

  8. UVa 10878 Decode the tape

    题目很简单,代码也很短.第一遍做的时候,我居然二乎乎的把input里面的小框框忽略掉了,所以WA了一次. 每一行代表一个二进制的ASCII码,'o'代表1,空格代表0,中间的小黑点忽略. 我直接把一行 ...

  9. HDU 2577 How to Type【DP】

    题意:给出一个字符串,有大写有小写,问最少的按键次数.然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭. dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态 然后就 ...

  10. POJ 2069 Super Star

    模拟退火. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...