codeforces Coder-Strike 2014 Round 1 A题解题报告

A. Poster
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
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
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.


题目大意:

        有一个长度为n的横幅,有n个字符,目前在k位置.而且一段时间内只能做出3种操作: 1. 左移; 2. 右移; 3. 画当前位置的字符.  三种操作的时间都一样

        求出需要完成这个横幅最短的消耗时间, 并输出操作步骤

解法:

        先移动到离当前位置最近的端点,然后再扫一遍.


代码:

#include <cstdio>

int n, k;
char st[110];

void init() {
	scanf("%d%d\n", &n, &k);
	for (int i = 1; i <= n; i++)  scanf("%c", &st[i]);
}

void solve() {
	if (k-1 < n-k) {
		for (int i = 1; i <= k-1; i++)  printf("LEFT\n");

		for (int i = 1; i < n; i++) {
			printf("PRINT %c\n", st[i]);
			printf("RIGHT\n");
		}
		printf("PRINT %c\n", st[n]);
	}
	else {
		for (int i = 1; i <= n-k; i++)  printf("RIGHT\n");

		for (int i = n; i > 1; i--) {
			printf("PRINT %c\n", st[i]);
			printf("LEFT\n");
		}
		printf("PRINT %c\n", st[1]);
	}
}

int main() {
	init();
	solve();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值