题目链接: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的更多相关文章

  1. 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1573   ...

  2. CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 解题报告:虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3 ...

  3. csuoj 1337: 搞笑版费马大定理

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 1337: 搞笑版费马大定理 Time Limit: 1 Sec  Memory Limit ...

  4. Codevs 1337 银行里的迷宫

    1337 银行里的迷宫 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 传送门 题目描述 Description 楚楚每一次都在你的帮助下过了一关又一关(比如他开 ...

  5. CSU 1337(费马大定理)

      CSU 1337 Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu   Descrip ...

  6. hdu 1337 The Drunk Jailer

    http://acm.hdu.edu.cn/showproblem.php?pid=1337 #include <cstdio> #include <cstring> #def ...

  7. [Noi2016]区间 BZOJ4653 洛谷P1712 Loj#2086

    额... 首先,看到这道题,第一想法就是二分答案+线段树... 兴高采烈的认为我一定能AC,之后发现n是500000... nlog^2=80%,亲测可过... 由于答案是求满足题意的最大长度-最小长 ...

  8. Loj #2192. 「SHOI2014」概率充电器

    Loj #2192. 「SHOI2014」概率充电器 题目描述 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品--概率充电器: 「采用全新纳米级加工技术,实现元件与导线能否通电完 ...

  9. Loj #3096. 「SNOI2019」数论

    Loj #3096. 「SNOI2019」数论 题目描述 给出正整数 \(P, Q, T\),大小为 \(n\) 的整数集 \(A\) 和大小为 \(m\) 的整数集 \(B\),请你求出: \[ \ ...

随机推荐

  1. cf515d

    题意:给出一个矩阵迷宫,要求用1×2的积木填满空白区域,问解法是否唯一,如果无解或者多解均输出“Not unique". 分析:广搜.看似二分图匹配但实际上不是. 我们认为每个点和上下左右四 ...

  2. 7.nodejs权威指南--加密与压缩

    1. 加密与压缩 1.1 加密 var crypto = require('crypto'); var text = "12345678"; var hasher = crypto ...

  3. 4.js模式-发布-订阅模式

    1. 发布-订阅模式 var observe = (function(){ var events = {}, listen, trigger, remmove; listen = function(k ...

  4. Python 之 【re模块的正则表达式学习】

    摘要: re模块包括操作正则表达式的函数,一些工作中都需要用到,现在说明下使用方法. 使用说明: 一,re模块下的函数:            函数             描述 compile(pa ...

  5. ABAP ALV单个单元格状态编辑-简单版本

    *&---------------------------------------------------------------------* *& Report  ZPPR0024 ...

  6. Match:Power Strings(POJ 2406)

     字符串前缀的阶 题目大意:求前缀的阶 和POJ1961是一样的,KMP的Next数组的应用,不要用STL,不要一个一个读入字符(IO永远是最慢的) #include <iostream> ...

  7. C# 对象操作

    //********************************************************************************* //************** ...

  8. 【编程题目】n 支队伍比赛,分别编号为 0,1,2。。。。n-1,已知它们之间的实力对比关系,

    36.引用自网友:longzuo(运算)谷歌笔试: 19n 支队伍比赛,分别编号为 0,1,2....n-1,已知它们之间的实力对比关系,存储在一个二维数组 w[n][n]中,w[i][j] 的值代表 ...

  9. 【matlab】libsvm-3.18安装与使用

    安装 1. 在http://www.csie.ntu.edu.tw/~cjlin/ 中下载libsvm 2. 按照http://zjhello123.blog.163.com/blog/static/ ...

  10. 【python】词法语法解析模块ply

    官方手册:http://www.dabeaz.com/ply/ply.html 以下例子都来自官方手册: 以四则运算为例: x = 3 + 42 * (s - t) 词法分析: 需要将其分解为: 'x ...