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\),请你求出: \[ \ ...
随机推荐
- robotFramework——截屏
测试执行过程中进行截屏并且保存,是任何一款自动化测试工具或者框架必备的功能.那么Robotframework如何进行截屏呢?Robotframework提供了一个“Screenshot”库. 使 ...
- Nginx反向代理到Tomcat服务器
在实际生产中,Tomcat服务器一般不单独使用在项目中,对于静态资源的响应Nginx表现的比较好,另外由于nginx是专门用于反向代理的服务器,所以很容易实现将java的请求转发到后端交给tomcat ...
- Java实现文件复制的四种方式
背景:有很多的Java初学者对于文件复制的操作总是搞不懂,下面我将用4中方式实现指定文件的复制. 实现方式一:使用FileInputStream/FileOutputStream字节流进行文件的复制操 ...
- 让UserControl能显示焦点状态
'set the control can display the focus status Protected Overrides Sub OnGotFocus(ByVal e As System.E ...
- iOS学习资源个人整理
1208更新: http://www.tuyiyi.com 图翼网 https://github.com/Alamofire/Al ...
- eclipse 注释模板
位置:window -> Preferences -> java -> Code Style -> Code Templates <?xml version=" ...
- Mysql 分区
关于分区操作,可参考:http://lobert.iteye.com/blog/1955841 这篇文章写的还是比较全面的. 关于Linear hash说明,可参考:http://www.bug315 ...
- java1.8中Lambda表达式reduce聚合测试例子
public class LambdaTest { public static void main(String[] args) { // 相当于foreach遍历操作结果值 Integer out ...
- python中读取\写入CSV中数据的方法
- Genymotion
@Genymotion相关文件下载地址 http://pan.baidu.com/s/1nu9nReh @虚拟机网络代理设置 Normal 0 7.8 磅 0 2 false false false ...