http://cdn.ac.nbutoj.com/Problem/view.xhtml?id=1541

When rain, nocLyt discovered a magical phenomenon that the rainwater always flow to the low-lying place.

我以后都在题解里放一小段题目,让人更容易搜到,有没有很有想法!(咦这样好像放全部的题目更容易被搜到啊)(不过那样好像比较乱啊)

[] Rainwater
时间限制: ms 内存限制: K
问题描述
When rain, nocLyt discovered a magical phenomenon that the rainwater always flow to the low-lying place. Now, there is a N * N grid matrix (four Unicom) and above the first row was constantly raining. I have to tell you some rules: . Each grid is solid (represented as black) initially, the rain cannot flow into the solid grid. . You can "Open" a grid, if you "Open" that grid, that grid will becomes hollow (represented as white). . Rainwater can flow from top to bottom and from left to right (also right to left), but the precondition is that they are both hollow grid. (grid fill with rainwater represented as blue) You can get more information from below picture. Figure: from left to right are executed times, times, times, times "Open" operation. We have three operation: . O i j: "Open" the grid (i, j). . F i j: You should tell me whether the grid(i, j) filled with rainwater. If yes, you should output , otherwise output . . C: You should tell me whether the rainwater has flow to the last row. If yes, you should output , otherwise output . Note: The grid matrix from top to bottom number to N, from left to right number to N. 输入
There are multiple test cases, each test case contains two positive integers N ( <= N <= ) and M ( <= M <= ).
Following M lines, each line contain one of the three operation:
. O i j ( <= i, j <= N)
. F i j ( <= i, j <= N)
. C 输出
Output the answer.
样例输入 O
F
O
F
C
O
C
样例输出 提示
无来源
nocLyt @SDAU

题目

我把题目隐藏成一行,这样就不乱,而且好像也能被搜到。不过这样格式有点逗,要看题目还是点链接去看好了。

好下面来说这题Rainwater:

看图比较容易懂意思,就是你的三种操作是开某个孔,查某个孔有没有进水,查最下面一行有没有水。水会从最上面一行出现,然后随便乱流,看最后一个图可以知道它会往上流。

看完题目,这不就是超水的深搜吗!

把地图从1开始,第0行先灌满水。每次开一块的时候,如果四个方向没水,那这一块肯定没水。如果有水,那就把这格填上水,并且深搜一波,把能到的地方都水了。这样每格最多水一次,复杂度超低。然后它询问某个孔的时候就直接答,询问最下面这行的话也直接答,搜的时候记得记最下面这行有没有水,不要在查的时候才查一整行,这个可是要问100W个问题的,地图只有5000*5000,最下面那一行有5000个格子啊,你敢每次搜一下吗!

总之就是搜就过啦,深搜王,我咧哇纳鲁!

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
const int MAXN=;
const int gx[]={,,-,};
const int gy[]={-,,,};
int a[MAXN][MAXN];
int n,m,flagc; void dfs(int x,int y)
{
int i;
a[x][y]=;
if(x==n) flagc=;
for(i=;i<;i++)
if(a[x+gx[i]][y+gy[i]]==) dfs(x+gx[i],y+gy[i]);
} void open(int x,int y)
{
int i,j;
if(a[x][y]!=) return;
a[x][y]=;
for(i=;i<;i++)
if(a[x+gx[i]][y+gy[i]]==){a[x][y]=;break;}
if(a[x][y]==) return;
dfs(x,y);
} int main()
{
char c;
int x,y,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(a,,sizeof(a));
for(i=;i<=n;i++)
a[][i]=;
flagc=;
for(i=;i<m;i++)
{
//cout<<i<<"!"<<endl;
do{scanf("%c",&c);}while(c=='\n' || c==' ');
if(c!='C')
{
scanf("%d%d",&x,&y);
if(c=='O') open(x,y);
else if (c=='F')
{
printf("%d\n",a[x][y]==);
}
}
else
{
printf("%d\n",flagc);
}
}
}
return ;
}

NBUT1541 Rainwater 题解的更多相关文章

  1. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  2. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  3. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  4. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  5. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  6. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  7. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  8. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

  9. CF100965C题解..

    求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...

随机推荐

  1. 利用Gulp优化部署Web项目[长文慎入]

    Gulp Gulp是一款项目自动化的构建工具,与Grunt一样可以通过创建任务(Task)来帮助我们自动完成一些工作流的内容.当然,今天我们的内容并不是讨论这二者的区别,仅仅是介绍介绍如何利用Gulp ...

  2. brew-cask之本地安装应用

    cask 固然好用,但是无奈很多资源在墙外,能下载的非常有限,就是能下载,也慢的要死.但是很多下载软件却可以下载这些资源,很奇怪,要么是有人FQ下载了,缓存到他们的服务器了,要么就是软件可以FQ下载. ...

  3. 有四中方法可以实现PHP的伪静态,你造吗?

    说起伪静态的实现方案,你是不是很爽快的回答"简单,配置下apache的重写规则就行了嘛" 但是你有没有发现这种情况,你最近弄了很多新功能,每天上几个新功能,每天都有好多伪静态配置, ...

  4. ThinkPHP中简单的CURD操作

    前言 我们通过一个简答例子来简述CURD的操作.首先看一下数据库的样子,其中id为自增行,其它是varchar 一.查询操作 首先,创建在Controller文件夹下创建一个User控制器,在该控制器 ...

  5. JavaScript基础---语言基础(3)

    流程控制语句 学习要点: 1.switch语句 2.for...in语句 3.break和continue语句 4.with语句 ECMA-262规定了一组流程控制语句.语句定义了ECMAScript ...

  6. Beta版本的贡献率

    陈志灏:负责ACTIVITY部分的编写,与服务器间数据交换,贡献率百分比:%30 尤志明:负责服务器PHP编写,以及一些JAVA编程方面的编译问题的解决,贡献率百分比:%40 周子淇:负责layout ...

  7. FZU5BOYS-Beta版本冲刺计划及安排

    1.下一阶段需要改进完善的功能 话题模块(分类参考Citeulike论文网站),文章/计划的删除功能 2.下一阶段新增的功能 1)推荐模块(冷启动问题,拟爬取部分豆瓣数据,部分伪专家数据(我们团队), ...

  8. 使用Ps制作透明ico

    准备好图片 打开Ps新建透明图片->抠取图片->复制粘贴 保存为gif格式->使用ico在线转换即可

  9. 创建Car类,实例化并调用Car类计算运输的原料量是否足够

    package dx; public class Car { //构造类 public Car() { System.out.println("Car的构造类"); } //构造类 ...

  10. 图解Android - Android GUI 系统 (2) - 窗口管理 (View, Canvas, Window Manager)

    Android 的窗口管理系统 (View, Canvas, WindowManager) 在图解Android - Zygote 和 System Server 启动分析一 文里,我们已经知道And ...