Codefoces 436 B. Om Nom and Spiders
纯属练习JAVA....
3 seconds
256 megabytes
standard input
standard output
Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.
The park can be represented as a rectangular n × m field. The park has k spiders,
each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding
direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.
Om Nom isn't yet sure where to start his walk from but he definitely wants:
- to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders);
- to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park).
We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.
Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see
during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell.
The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)).
Each of the next n lines contains m characters —
the description of the park. The characters in the i-th line describe the i-th
row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the
line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R"
(a spider moving right), "U" (a spider moving up), "D" (a
spider moving down).
It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders.
Print m integers: the j-th integer must show the
number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to
right.
3 3 4
...
R.L
R.U
0 2 2
2 2 2
..
RL
1 1
2 2 2
..
LR
0 0
3 4 8
....
RRLL
UUUU
1 3 3 1
2 2 2
..
UU
0 0
Consider the first sample. The notes below show how the spider arrangement changes on the field over time:
... ... ..U ...
R.L -> .*U -> L.R -> ...
R.U .R. ..R ...
Character "*" represents a cell that contains two spiders at the same time.
- If Om Nom starts from the first cell of the first row, he won't see any spiders.
- If he starts from the second cell, he will see two spiders at time 1.
- If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2.
import java.util.*; public class Main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
int n=cin.nextInt(),m=cin.nextInt(),k=cin.nextInt();
String[] mp=new String[n];
for(int i=0;i<n;i++)
mp[i]=cin.next();
int[] ans=new int[m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
char c=mp[i].charAt(j);
if(c=='U')
{
if(i%2==0)
ans[j]++;
}
else if(c=='R')
{
int t=i+j;
if(t<m)
ans[t]++;
}
else if(c=='L')
{
int t=j-i;
if(t>=0)
ans[t]++;
}
}
}
StringBuilder RET=new StringBuilder();
for(int i=0;i<m;i++)
{
RET.append(ans[i]+" ");
}
System.out.println(RET);
}
}
Codefoces 436 B. Om Nom and Spiders的更多相关文章
- CF Zepto Code Rush 2014 B. Om Nom and Spiders
Om Nom and Spiders time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Zepto Code Rush 2014 B - Om Nom and Spiders
注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
B. Om Nom and Dark Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- ZeptoLab Code Rush 2015 B. Om Nom and Dark Park
Om Nom is the main character of a game "Cut the Rope". He is a bright little monster who l ...
- C. Om Nom and Candies 巧妙优化枚举,将复杂度控制在10e6
C. Om Nom and Candies 无线超大背包问题 #include <iostream> #include <cstdio> #include <cstrin ...
- B. Om Nom and Dark Park
B. Om Nom and Dark Park 在满二叉树上的某些边上添加一些值.使得根节点到叶子节点的路径上的权值和都相等.求最少需要添加多少. 我们利用性质解题. 考察兄弟节点.由于他们从跟节 ...
- Codeforces 526D - Om Nom and Necklace 【KMP】
ZeptoLab Code Rush 2015 D. Om Nom and Necklace [题意] 给出一个字符串s,判断其各个前缀是否是 ABABA…ABA的形式(A和B都可以为空,且A有Q+1 ...
- Codeforces - ZeptoLab Code Rush 2015 - D. Om Nom and Necklace:字符串
D. Om Nom and Necklace time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces C - Om Nom and Candies
C - Om Nom and Candies 思路:贪心+思维(或者叫数学).假设最大值max(wr,wb)为wr,当c/wr小于√c时,可以枚举r糖的数量(从0到c/wr),更新答案,复杂度√c:否 ...
随机推荐
- 前端基础入门第一阶段-Web前端开发基础环境配置
Web前端和全栈的定义: A.什么是传统传统web前端:需要把设计师的设计稿,切完图,写标签和样式,实现JS的效果,简而言之即只需要掌握HTML的页面结构,CSS的页面样式,javaScript页面的 ...
- JavaScript/JQuery radioButton(单选按钮)练习20190409
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- xshell通过xftp传输Windows文件到Linux:在输入put后,再摁 TAB 键,可显示当前文件夹的文件
在输入put后,再摁 TAB 键,可显示当前文件夹的文件 sftp:/home/yan> put $Recycle.Bin\ BluestacksCN\ ...
- zabbix监控流程图
- POJ 1463 Strategic game(树形DP入门)
题意: 给定一棵树, 问最少要占据多少个点才能守护所有边 分析: 树形DP枚举每个点放与不放 树形DP: #include<cstdio> #include<iostream> ...
- OI中的小智慧
反正不会咕咕的. sort之类没+1的问题不说 双向边n*2的问题不说 变量n+5的问题不说 1.先生成后判断 (见NOIP 2016 pj t2回文日期) 这个思想在这道题体现的不明显,记得洛谷上面 ...
- 大数据学习——采集文件到HDFS
采集需求:比如业务系统使用log4j生成的日志,日志内容不断增加,需要把追加到日志文件中的数据实时采集到hdfs 根据需求,首先定义以下3大要素 l 采集源,即source——监控文件内容更新 : ...
- 大数据学习——VMware安装
---恢复内容开始--- 一.下载VMware,安装 二.新建虚拟机 1.FIle-->new virtual machine 后面进入硬件资源分配,其中cpu给1个,内存至少给1G,网卡的选择 ...
- Python+selenium登录测试
我们以登录新浪微博为案例来讲解,首先进入登录页面,输入用户名和密码,点击登录按钮,并且获得用户信息以验证是否登录成功. Web地址:https://login.sina.com.cn/signup/s ...
- asp.net静态变量研究
asp.net的webform,请求一个页面,如index.aspx,每一次都会交给不同的线程来处理. 经过个人测试,不管是页面类的静态属性,还是工具类的静态属性,都不会因为session的过期而改变 ...