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\),请你求出: \[ \ ...
随机推荐
- Qt5.4 MSVC mysql驱动编译;
http://www.mysql.com/ 下载mysql http://download.qt.io/archive/qt/ Qt 下载 1. mysql安装源码 注意勾选这一步,将mysq ...
- 8.SpringMVC参数传递
页面参数传递到controller, 可被同名(与页面标签上的name名对应)的参数接收,用request设值,页面再取出来. 注意乱码解决办法: ①如果是get提交,则在tomcat的server. ...
- codeforces 425D Sereja and Squares n个点构成多少个正方形
输入n个点,问可以构成多少个正方形.n,xi,yi<=100,000. 刚看题的时候感觉好像以前见过╮(╯▽╰)╭最近越来越觉得以前见过的题偶尔就出现类似的,可是以前不努力啊,没做出来的没认真研 ...
- LeetCode 202 Happy Number
Problem: Write an algorithm to determine if a number is "happy". A happy number is a numbe ...
- 如何获得images.xcassets 中图片的路径?
UIImage加载图片的方式以及Images.xcassets对于加载方法的影响 重点: Images.xcassets中的图片资源只能通过imageNamed:方法加载,通过NSBundle的pat ...
- Android Studio新建了一个项目提示Error:Unable to start the daemon process
提示如下错误:
- Hibernate双向多对多对象关系模型映射
1 双向many-to-many 业务模型: 描述员工和项目 一个员工同时可以参与多个项目 一个项目中可以包含多个员工 分析:数据库的数据模型,通过中间关系表,建立两个one-to-many构成man ...
- ios二维码生成
二维码扫描现在已经有很多的库可以使用了,常用的有ZXing和ZBar.如果感兴趣的同学可以自行研究. libqrencode介绍:是一个用C语言编写的用来解析二维条形码(QR Code)的程序库,li ...
- 单击双击手势(UITapGestureRecognizer)
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...
- August 9th 2016, Week 33rd Tuesday
Tomorrow is never clear, our time is here. 明天是未知的,我们还是要过好当下. Tomorrow is not unpredictable, it is cl ...