codeforces 412A Poster
来源:互联网 发布:php单例模式代码 编辑:程序博客网 时间:2024/04/30 15:28
Description
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”;
“PRINTx” (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 Input
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
Hint
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.
题意:公司要为大标题上色,给出标题的长度,接着给出标题,移动梯子的代价是比较大的,所以要求找到最小的移动方案为标题的每个字上色。
思路:将梯子移动至较为靠近的一边,然后逐个输出即可。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){ int n,k; cin>>n>>k; char a[n+1]; for(int i=1;i<=n;i++) cin>>a[i]; if(n>=2*k) { for(int i=k;i>1;i--) { cout<<"LEFT"<<endl; } for(int i=1;i<=n;i++) { if(i!=n) { printf("PRINT %c\nRIGHT\n",a[i]); } else printf("PRINT %c\n",a[i]); } } if(n<2*k) { for(int i=k;i<n;i++) { cout<<"RIGHT"<<endl; } for(int i=n;i>=1;i--) { if(i!=1) { printf("PRINT %c\nLEFT\n",a[i]); } else printf("PRINT %c\n",a[i]); } } return 0;}
- codeforces 412A Poster
- Codeforces 412A Poster(贪心)
- 截图(Grabbing a Poster Frame)
- poster
- Poster Design
- CodeForces-a
- Codeforces 903A A
- CodeForces 412(A,B,C,D,E)
- Codeforces Round #412 ( Div. 2)A+B
- Codeforces Round #412 A. Is it rated?
- Poster Design II
- 典型代表 Poster child
- Flex Error Classes Poster
- 如何做Poster
- poster add on
- Experience for making poster
- 火狐 poster初运用
- 火狐的poster工具
- 菜鸟学Java----基本类型及其封装类
- 关于switch语句中省略break语句的问题
- ViewPager
- objective - C 下字符串的处理方法
- Linux压缩解压缩文章总结
- codeforces 412A Poster
- nyoj 诡异的电梯【Ⅰ】 1070 (DP) 好题
- 编译原理与技术(第四章)语法分析
- hdu 3466 Proud Merchants
- 拉丁矩阵问题
- 关于CocoaPods的使用小说明
- Palindrome Number
- git命令行提交代码(因为某些原因Eclipse不能提交代码,所以改用git命令)
- hdoj3664Permutation Counting【递推】