loj 1337
题目链接:http://lightoj.com/volume_showproblem.php?problem=1337
思路:对于搜过的区域进行标记,如果要求的点落在已经搜过的区域,那么直接取出来即可,否则,就dfs一下。
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std; const int MAXN = ( + );
int n, m, Q, _count, cnt;
char map[MAXN][MAXN];
int mark[MAXN][MAXN];
vector<int >ans;
int dir[][] = { { -, }, { , }, { , - }, { , } }; void dfs(int x, int y)
{
mark[x][y] = _count;
if (map[x][y] == 'C') cnt++;
for (int i = ; i < ; i++) {
int xx = x + dir[i][];
int yy = y + dir[i][];
if (xx >= && xx < n && yy >= && yy < m && map[xx][yy] != '#') {
if (mark[xx][yy] == -)dfs(xx, yy);
}
}
} int main()
{
int _case, t = ;
scanf("%d", &_case);
while (_case--) {
scanf("%d %d %d", &n, &m, &Q);
for (int i = ; i < n; i++) {
scanf("%s", map[i]);
}
memset(mark, -, sizeof(mark));
ans.clear();
_count = -;
printf("Case %d:\n", t++);
while (Q--) {
int x, y;
scanf("%d %d", &x, &y);
x--, y--;
if (map[x][y] == '#') {
puts("");
}
else if (mark[x][y] == -) {
_count++;
cnt = ;
dfs(x, y);
ans.push_back(cnt);
printf("%d\n", cnt);
}
else {
printf("%d\n", ans[mark[x][y]]);
}
}
}
return ;
}
loj 1337的更多相关文章
- 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1573 ...
- CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 解题报告:虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3 ...
- csuoj 1337: 搞笑版费马大定理
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 1337: 搞笑版费马大定理 Time Limit: 1 Sec Memory Limit ...
- Codevs 1337 银行里的迷宫
1337 银行里的迷宫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 传送门 题目描述 Description 楚楚每一次都在你的帮助下过了一关又一关(比如他开 ...
- CSU 1337(费马大定理)
CSU 1337 Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu Descrip ...
- hdu 1337 The Drunk Jailer
http://acm.hdu.edu.cn/showproblem.php?pid=1337 #include <cstdio> #include <cstring> #def ...
- [Noi2016]区间 BZOJ4653 洛谷P1712 Loj#2086
额... 首先,看到这道题,第一想法就是二分答案+线段树... 兴高采烈的认为我一定能AC,之后发现n是500000... nlog^2=80%,亲测可过... 由于答案是求满足题意的最大长度-最小长 ...
- Loj #2192. 「SHOI2014」概率充电器
Loj #2192. 「SHOI2014」概率充电器 题目描述 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品--概率充电器: 「采用全新纳米级加工技术,实现元件与导线能否通电完 ...
- Loj #3096. 「SNOI2019」数论
Loj #3096. 「SNOI2019」数论 题目描述 给出正整数 \(P, Q, T\),大小为 \(n\) 的整数集 \(A\) 和大小为 \(m\) 的整数集 \(B\),请你求出: \[ \ ...
随机推荐
- JQ添加标签
<script type="text/javascript" src="http://files.cnblogs.com/914556495wxkj/jquery- ...
- nginx server中的server_name配置的域名在客户机上无法访问
nginx配置如下: nginx.conf: #user nobody; worker_processes 2; #error_log logs/error.log; #error_log logs/ ...
- 安装CentOS 7时出现No Caching mode page found问题的解决
将CentOS 7镜像刻到U盘之后,向服务器安装时,使用U盘启动会出现两种启动选项,一种是UEFI启动选项,一种是默认的启动选项,如果不使用UEFI方式安装,那么一般是没有问题的,如果选择UEFI方式 ...
- Windows下配置Java开发环境
学习Java第一步是配置本地开发环境,学习最基本的桌面开发,下面以win7为例配置Java开发环境,即:JDK+JRE+Eclipse,安装JDK的时候会默认安装JRE,根据提示安装就可以了. 首先去 ...
- delphi控件属性大全-详解-简介
http://blog.csdn.net/u011096030/article/details/18716713 button 组件: CAPTION 属性 :用于在按钮上显示文本内容 Cancel ...
- codeforces 460D Little Victor and Set(构造、枚举)
最近的CF几乎都没打,感觉挺水的一个题,不过自己仿佛状态不在,看题解才知道做法. 输入l, r, k (1 ≤ l ≤ r ≤ 1012; 1 ≤ k ≤ min(106, r - l + 1)). ...
- 【leetcode】Reverse Linked List II (middle)
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
- August 17th 2016 Week 34th Wednesday
Life is painting a picture, not doing a sum. 生活就像是绘画,而不是做算术. I am too serious about digits. All what ...
- NYOJ题目768移位密码
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtIAAAJqCAIAAACJkTDlAAAgAElEQVR4nO3du3Ljvpa34b4J574Qx7
- 关于s:iterator 和s:if 的结合使用
<s:iterator value="list" status="st"> <div class="sidebar-nav" ...