纯属练习JAVA....

B. Om Nom and Spiders
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Sample test(s)
input
3 3 4
...
R.L
R.U
output
0 2 2 
input
2 2 2
..
RL
output
1 1 
input
2 2 2
..
LR
output
0 0 
input
3 4 8
....
RRLL
UUUU
output
1 3 3 1 
input
2 2 2
..
UU
output
0 0 
Note

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);
}
}

最新文章

  1. Android事件处理
  2. 二十、【.Net开源】EFW框架核心类库之WebService服务
  3. Redis设计与实现-附加功能
  4. DataGridView 绑定数据后修改列类型
  5. Flex布局摆脱float带来的布局问题
  6. Android最方便的数据库--LitePal
  7. Kafka的常用管理命令
  8. MVC无刷新分页
  9. 学号:201521123116 《java程序设计》第五周学习总结
  10. linux(3)磁盘与文件系统管理/查看硬盘、内存空间/文件系统的操作/ 文件的压缩和打包
  11. sublime test2 快捷键
  12. Pythoy 数据类型序列化——json&amp;pickle 模块
  13. vue-quill-editor富文本编辑器,上传图片自定义为借口上传
  14. python 方法
  15. 在IIS上安装 thinkphp的方法
  16. $trainClassLayer.find(&#39;input[name=data-item-checkbox]&#39;).eq(index).change();//激活第index+1那个checkbox
  17. 如何将.NET 4.0写的Windows service和Web API部署到docker上面
  18. hibernate联合主键注解方式
  19. (转)用stunnel给普通http通信加密
  20. tp5中捕获异常的配置

热门文章

  1. Java中wait()方法为什么要放在同步块中?(lost wake-up 问题)
  2. JavaSE-28 hashCode()方法、equals()方法和==相关概念
  3. Perl: hash散列转换为Json报错集, perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
  4. web.config中配置数据库连接的两种方式
  5. Omnidirectional DSO: Direct Sparse Odometry with Fisheye Cameras 论文摘要
  6. 1、C编程预备计算机知识
  7. 关于Error:Maven&#160;Resources&#160;Compiler:&#160;Maven&#160;project&#160;configuration&#160;required&#160;for&#160;module&#160;&#39;项目名&#39;&#160;isn&#39;t&#160;available.&#160;Compilation&#160;of&#160;Maven&#160;projects&#160;is&#160;supported&#160;only&
  8. luogu 1608 路径统计--最短路计数
  9. 【转载】Sql语句用left join 解决多表关联问题(关联套关联,例子和源码)
  10. 如何用纯 CSS 为母亲节创作一颗像素画风格的爱心