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的更多相关文章
随机推荐
- IaaS、PaaS、SaaS是云计算的三种服务模式
IaaS.PaaS.SaaS是云计算的三种服务模式 1. SaaS:Software-as-a-Service(软件即服务)提供给客户的服务是运营商运行在云计算基础设施上的应用程序,用户可以在各种设备 ...
- 用Fiddler模拟低速网络环境【转】
原文链接:http://caibaojian.com/fiddler.html 我们为什么要限速 限速对于web前端研发是非常重要的,由于开发者的机器一般配置都很高,并且是在localhost下来调试 ...
- z-index神奇的失效了!!!
z-index简单介绍 首先z-index只对定位元素有效,什么是定位元素呢,也就是设置了position属性的元素,position:relative--相对定位,position:absolute ...
- O054、Attach Volume 操作(Part II)
参考https://www.cnblogs.com/CloudMan6/p/5631328.html 计算节点作为iSCSI initiator 访问存储节点 iSCSI Target 上的v ...
- js之数据类型(对象类型——构造器对象——函数1)
函数它只定义一次,但可能被多次的执行和调用.JavaScript函数是参数化的,函数的定义会包括形参和实参.形参相当于函数中定义的变量,实参是在运行函数调用时传入的参数. 一.函数定义 函数使用fun ...
- 关于javascript的事件执行机制理解
理解javascript事件执行机制 众所周知,js是一个单线程的语言,这意味着同一时间只能做一件事,但是我们又说js是异步的.首先,单线程并不是没有优点.作为浏览器脚本语言,JavaScript 的 ...
- React+Redux+Dva学习
Redux提供一些api来管理数据,并且只能通过它提供的方式来修改.Redux包括三个部分:store, action,reducer. store:是一个规范的state,就像一个有条理的数据库,R ...
- go语言中获取变量类型的三种方法
package main import ( "fmt" "reflect" ) func main() { var num float64 = 3.14 // ...
- centos7常见问题(更新。。。)
1.网络设置 装好CentOS7后,我们一开始是上不了网的 DHCP 这时候,可以输入命令dhclient,可以自动获取一个IP地址,再用命令ip addr查看IP 不过这时候获取的IP是动态的,下次 ...
- 终端复用工具-tmux
目录 终端复用工具--Tmux 一.为什么要用Tmux? 二.tmux是什么? 三.Tmux基本概念 四.Tmux使用规则 1.安装Tmux 2.基本使用 3.自定义配置文件 五.补充 1.tmux ...