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

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

/*
* 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. ORACLE基本语法

    ORACLE基本语法 一.ORACLE的启动和关闭1.在单机环境下要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下su - oraclea.启动ORACLE系统oracle>s ...

  2. 294. Flip Game II

    题目: You are playing the following Flip Game with your friend: Given a string that contains only thes ...

  3. DataGridView过滤区分大小写问题

    DataTable上的过滤方法: 一.可以用DataTable.Select("条件"),返回DataRow[]格式的结果集. DataRow[] drArr = dt.Selec ...

  4. js收藏

    //设为主页function SetHome(obj, vrl) { try { obj.style.behavior = 'url(#default#homepage)'; obj.setHomeP ...

  5. Entity Framework Architecture

    http://www.entityframeworktutorial.net/EntityFramework-Architecture.aspx The following figure shows ...

  6. [HDOJ2512]一卡通大冒险(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2512 给一个数n,问1~n这n个数内的划分.设dp(i,j)为i划分为j个集合时有多少个. 初始化条件 ...

  7. IE下easyui 缓存问题

    $.ajaxSetup ({   cache: false //关闭AJAX相应的缓存 }); 这一句话就足够了,很管用!

  8. git大文件管理

    由于git在每一个commit时都会变动过的文件全部保存(不像其他的系统,只做文件增量存储),外加未变动文件的引用,这样如果在文件系统中有一些大的二进制文件,比如图片,视频,那么很快你的repo就将变 ...

  9. 【笨嘴拙舌WINDOWS】窗体样式

    "眼睛是人类心灵的窗口,打开窗口,你就能看到整个世界" 在PC时代,计算机的显示屏就是真个世界,WINDOWS将真个世界分解为一个个的窗口,每个窗口有自己的容貌,下面我们将一一揭开 ...

  10. ubuntu 11.04 源 更新不了,全显示ign、404

    原文地址:http://blog.csdn.net/enjio/article/details/11603373   ubuntu 11.04 源 更新不了 分类: 开发相关2013-09-12 14 ...