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:否 ...
随机推荐
- dockerfile 的最佳实践
Dockerfile 编写nginx容器 [root@mast nginx]# cat Dockerfile FROM centos MAINTAINER zhaoruidong RUN yum -y ...
- largest rectangle in histogram leetcode
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- 项目中常用的js方法(持续更新)
<script> var utils = { //时间戳转日期(timestamp:时间戳 默认当前时间) dateFormat: function(timestamp = new Dat ...
- 数的计数(noip2001,动态规划递推)
题目链接: 普通版: https://www.luogu.org/problemnew/show/P1028 数据加强版: https://www.luogu.org/problemnew/show/ ...
- jdk环境变量配置至第一个简单程序运行成功
桌面右键单击我的电脑,属性,高级,环境变量,然后再系统变量中配置(也可在用户变量中配置) 在配置环境变量时限查看是否已存在变量名称,有则添加路径,没有则创建再添加路径 /* JAVA_HOME% C: ...
- kvm客户机存储方式
前面介绍了存储的配置和qemu-img工具来管理镜像,在QEMU/KVM中,客户机镜像文件可以由很多种方式来构建,其中几种如下: 1) 本地存储的客户机镜像文件. 2) 物理磁盘或磁盘分区. 3) L ...
- Linux组和提权
目 录 第1章 组命名管理** 1 1.1 group组信息和密码信息 1 1.1.1 /etc/group 组账户信息 1 1.1.2 /etc/gshadow 组密码信息 ...
- C语言之static用法
1,static修饰全局变量 限定变量的作用域.被static修饰的全局变量存储域不变,依然存储在静态存储区,即bss段或data段.但作用域发生改变,被static修饰全局变量只能被本文件的函数访问 ...
- JAVA:windows myeclipse jdk tomcat maven 完美搭建
文章来源:http://www.cnblogs.com/hello-tl/p/8305027.html 0.下载所需安装包 jdk-7u71-windows-x64.exe 链接:http://p ...
- Oracle获取最近执行的SQL语句
注意:不是每次执行的语句都会记录(如果执行的语句是能在该表找到的则ORACLE不会再次记录,就是说本次执行的语句和上次或者说以前的语句一模一样则下面语句就查不出来的): select last_loa ...