codeforces412A
Poster
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.
The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.
Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.
Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
Input
The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
Output
In t lines, print the actions the programmers need to make. In the i-th line print:
- "LEFT" (without the quotes), if the i-th action was "move the ladder to the left";
- "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right";
- "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder".
The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
Examples
2 2
R1
PRINT 1
LEFT
PRINT R
2 1
R1
PRINT R
RIGHT
PRINT 1
6 4
GO?GO!
RIGHT
RIGHT
PRINT !
LEFT
PRINT O
LEFT
PRINT G
LEFT
PRINT ?
LEFT
PRINT O
LEFT
PRINT G
Note
Note that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
sol:无脑模拟即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m;
char S[N];
int main()
{
int i;
R(n); R(m);
scanf("%s",S+);
if(m-<n-m)
{
for(i=;i<m;i++) puts("LEFT");
for(i=;i<n;i++)
{
cout<<"PRINT "; putchar(S[i]); putchar('\n'); puts("RIGHT");
}
cout<<"PRINT "; putchar(S[n]);
}
else
{
for(i=m;i<n;i++) puts("RIGHT");
for(i=n;i>;i--)
{
cout<<"PRINT "; putchar(S[i]); putchar('\n'); puts("LEFT");
}
cout<<"PRINT "; putchar(S[]);
}
return ;
}
/*
Input
2 2
R1
Output
PRINT 1
LEFT
PRINT R Input
2 1
R1
Output
PRINT R
RIGHT
PRINT 1 Input
6 4
GO?GO!
Output
RIGHT
RIGHT
PRINT !
LEFT
PRINT O
LEFT
PRINT G
LEFT
PRINT ?
LEFT
PRINT O
LEFT
PRINT G
*/
codeforces412A的更多相关文章
随机推荐
- Java 多线程创建和线程状态
一.进程和线程 多任务操作系统中,每个运行的任务是操作系统运行的独立程序. 为什么引进进程的概念? 为了使得程序能并发执行,并对并发执行的程序加以描述和控制. 因为通常的程序不能并发执行,为使程序(含 ...
- devXpress ribbonForm处理
1.图标处理 这个图标是通过 Element Ribbon API
- npm安装淘宝镜像cnpm
在cmd中执行 npm install -g cnpm --registry=https://registry.npm.taobao.org
- jquery文件上传版 插件
/*! * jQuery Form Plugin * version: 4.2.2 * Requires jQuery v1.7.2 or later * Project repository: ht ...
- SQLplus命令中删除键和翻页键不能用的问题
问题现象: 在进入连接数据库后,如何写错命令,删除键不好使,总是出现^H^H [oracle@master2 ~]$ sqlplus / as sysdba SQL*Plus: Release 12. ...
- ubuntu install opencv
1. install the newest opencv version pip install opencv-python
- 第七章·Logstash深入-收集NGINX日志
1.NGINX安装配置 源码安装nginx 因为资源问题,我们先将nginx安装在Logstash所在机器 #安装nginx依赖包 [root@elkstack03 ~]# yum install - ...
- 4.3. Scrapy Shell
Scrapy Shell:模拟scrapy去发送请求 Scrapy终端是一个交互终端,我们可以在未启动spider的情况下尝试及调试代码,也可以用来测试XPath或CSS表达式,查看他们的工作方式,方 ...
- windows漏洞MS03_026
话不多说,直接进入正题 第一步查看是否能ping通,第二步就是扫描端口,开放了端口才能进行攻击 linux进入msfconsole,搜索03_026 search 03_026 等待一会,返回漏洞的全 ...
- Android异常与性能优化相关面试问题-ANR异常面试问题详解
什么是ANR? Application Not Responding 造成ANR的主要原因: 应用程序的响应性是由ActivityManager和WindowManager系统服务监视的,当监视到在A ...