纯属练习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);
}
}

Codefoces 436 B. Om Nom and Spiders的更多相关文章

  1. 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 ...

  2. Zepto Code Rush 2014 B - Om Nom and Spiders

    注意题目给的是一个nxm的park,设元素为aij,元素aij 有4种可能U(上移),D(下移),L(左移),R(右移) 假设第i行第j列元素aij(注意元素的索引是从0开始的) 当aij为D时,此时 ...

  3. 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 ...

  4. 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 ...

  5. C. Om Nom and Candies 巧妙优化枚举,将复杂度控制在10e6

    C. Om Nom and Candies 无线超大背包问题 #include <iostream> #include <cstdio> #include <cstrin ...

  6. B. Om Nom and Dark Park

    B. Om Nom and Dark Park 在满二叉树上的某些边上添加一些值.使得根节点到叶子节点的路径上的权值和都相等.求最少需要添加多少. 我们利用性质解题.   考察兄弟节点.由于他们从跟节 ...

  7. Codeforces 526D - Om Nom and Necklace 【KMP】

    ZeptoLab Code Rush 2015 D. Om Nom and Necklace [题意] 给出一个字符串s,判断其各个前缀是否是 ABABA…ABA的形式(A和B都可以为空,且A有Q+1 ...

  8. 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 ...

  9. Codeforces C - Om Nom and Candies

    C - Om Nom and Candies 思路:贪心+思维(或者叫数学).假设最大值max(wr,wb)为wr,当c/wr小于√c时,可以枚举r糖的数量(从0到c/wr),更新答案,复杂度√c:否 ...

随机推荐

  1. mysql时间的处理

    mysql中格式化时间为: 1,DATE_FORMAT(APPLYDATE,'%Y-%m-%d %H:%i:%S') AS APPLYDATE 2,DATE_FORMAT(CHKSIGNDATE, ' ...

  2. C# 如何正确删除List中的item

    参考博客 https://blog.csdn.net/Le_Sam/article/details/75633737 https://www.cnblogs.com/hedianzhan/p/9130 ...

  3. 洛谷 P2337 【[SCOI2012]喵星人的入侵】

    这几天一直在刷插头Dp,写了几道入门题后,觉得还比较水,直到我发现了这一题.... 题目大意:给你一个n*m的地图,有些是空地,有些是障碍,还有两个是ST,在给你一个L,代表可以放L个炮台,你要在空地 ...

  4. POJ-1328-放置雷达

    这是一道贪心的题目,首先我们要知道,我们放置雷达的话我们可以做一个转换,就是已知岛屿的点坐标的时候,我们可以算一下,这个点以d为半径与x轴交点之间的线段在x轴上的投影,然后我们只需要在这个投影范围内设 ...

  5. Redis主从配置与数据备份还原

    一.主从配置: 1.下载: wget http://download.redis.io/releases/redis-4.0.9.tar.gz tar xzf redis-4.0.9.tar.gz c ...

  6. Django 动态建表

    #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Random_lee # -*- coding: utf-8 -*- from django ...

  7. 【Codeforces 1141E】Superhero Battle

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 二分最后轮了几圈. 二分之后直接o(N)枚举具体要多少时间即可. 注意爆long long的情况. 可以用对数函数,算出来有多少个0 如果大于 ...

  8. bzoj 1500 [NOI 2005] 维修数列

    题目大意不多说了 貌似每个苦逼的acmer都要做一下这个splay树的模版题目吧 还是有很多操作的,估计够以后当模版了.... #include <cstdio> #include < ...

  9. bzoj 4736 /uoj274【清华集训2016】温暖会指引我们前行 lct

    [清华集训2016]温暖会指引我们前行 统计 描述 提交 自定义测试 寒冬又一次肆虐了北国大地 无情的北风穿透了人们御寒的衣物 可怜虫们在冬夜中发出无助的哀嚎 “冻死宝宝了!” 这时 远处的天边出现了 ...

  10. bzoj3142[Hnoi2013]数列 组合

    Description 小 T最近在学着买股票,他得到内部消息:F公司的股票将会疯涨.股票每天的价格已知是正整数,并且由于客观上的原因,最多只能为N.在疯涨的K天中小T观察 到:除第一天外每天的股价都 ...