hdu 5254 水题
纯暴力就能过的,可是题目描述真心不清楚,我看了好久好久才明白题目啥意思。
为了迅速打完,代码比较冗余。
/*
* 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 水题的更多相关文章
- HDU-1042-N!(Java大法好 && HDU大数水题)
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Subm ...
- HDU 5391 水题。
E - 5 Time Limit:1500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 1544 水题
水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...
- HDU排序水题
1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...
- hdu 2710 水题
题意:判断一些数里有最大因子的数 水题,省赛即将临近,高效的代码风格需要养成,为了简化代码,以后可能会更多的使用宏定义,但是通常也只是快速拿下第一道水题,涨自信.大部分的代码还是普通的形式,实际上能简 ...
- Dijkstra算法---HDU 2544 水题(模板)
/* 对于只会弗洛伊德的我,迪杰斯特拉有点不是很理解,后来发现这主要用于单源最短路,稍稍明白了点,不过还是很菜,这里只是用了邻接矩阵 套模板,对于邻接表暂时还,,,没做题,后续再更新.现将这题贴上,应 ...
- hdu 5162(水题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5162 题解:看了半天以为测试用例写错了.这题玩文字游戏.它问的是当前第i名是原数组中的第几个. #i ...
- hdu 3357 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...
- hdu 5038 水题 可是题意坑
http://acm.hdu.edu.cn/showproblem.php?pid=5038 就是求个众数 这个范围小 所以一个数组存是否存在的状态即可了 可是这句话真恶心 If not all ...
随机推荐
- DB2中字符、数字和日期类型之间的转换
DB2中字符.数字和日期类型之间的转换 一般我们在使用DB2或Oracle的过程中,经常会在数字<->字符<->日期三种类 型之间做转换,那么在DB2和Oracle中,他们分别 ...
- Two Sigma OA
刚做了两道Two Sigma OA. 还是两道老题, Friend Cycle和Longest Chain. Friend Cycle可以用Union Find来做.优化的时候因为矩阵是沿对角线对称, ...
- CentOS增加硬盘
1.查看新硬盘 #fdisk –l 新添加的硬盘的编号为/dev/sdb 2.硬盘分区 1)进入fdisk模式 #/sbin/fdisk /dev/sdb 2 ...
- Linux系统文件访问控制列表
linux系统中的RWX权限.特殊权限.隐藏权限都是对某一类用户设置的, 而如果希望对某个指定的用户进行单独的权限设置的话就需要用到文件的 访问控制权限了. 我们可以对普通文件或目录进行设置ACL,通 ...
- jdk、apache-ant结合yuicompressor配置的CSS与JS合并压缩工具
前序:网上很多css与js合并打包工具,其中最流行的就是ant结合yui-compressor,鉴于学习与工作需要今天就学习了一下这种方式,供大家学习交流. 步骤:1.安装jdk,并配置其变量环境:有 ...
- uva 10048 Audiophobia(最小生成树)
题目链接:10048 - Audiophobia 题目大意:有n个城市,和m条街道,每条街道有一个噪音值,q次去问,从城市a到城市b,路径上分贝值的最大值最小为多少. 解题思路:与uva 10099的 ...
- vmware 虚拟机 桥接 设置静态 IP
最简单的方式: 图形界面下,进入设置IP的地方,设置一个静态IP. 然后再转入命令行继续工作.. 不行就 重启
- 35.3wCF编程
1.新建一个空白的解决方案文件,然后添加新建项目,项目类型为WCF服务应用程序,CH35Ex01 2.添加新建控制台应用程序Ch35Ex01Client 3.生成解决方案 4.右键Ch35Ex01Cl ...
- 在Java中直接调用js代码
JDK1.6版添加了新的ScriptEngine类,允许用户直接执行js代码. 在Java中直接调用js代码 不能调用浏览器中定义的js函数,会抛出异常提示ReferenceError: “alert ...
- ubuntu 中 ssh连接用UTF-8
在ubuntu中,文本模式的终端默认情况下是无法显示中文的,尽管有些解决办法,但通常情况下都不是很如意.这时,我们可能会采用英文终端,但当我们用ssh连接的时候,又想用中文的.每次都改是个麻烦事.于是 ...