cf(412A,B,C)

202 篇文章 0 订阅
42 篇文章 0 订阅

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.


这真的很水。。。

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;

char a[150];

int main()
{
    int n,k;
    cin>>n>>k>>a;
    if(k!=1&&k!=n)
    {
        if(n-k>k-1)
        {
            for(int i=0;i<k-1;i++)
            cout<<"LEFT"<<endl;
            k=1;
        }
        else
        {
            for(int i=0;i<n-k;i++)
            cout<<"RIGHT"<<endl;
            k=n;
        }
    }
    int l=strlen(a);
    if(k==1)
    {
        for(int i=0;i<l-1;i++)
            printf("PRINT %c\nRIGHT\n",a[i]);
        printf("PRINT %c\n",a[l-1]);
    }
    else
    {
        for(int i=l-1;i>0;i--)
            printf("PRINT %c\nLEFT\n",a[i]);
        printf("PRINT %c\n",a[0]);
    }
    return 0;
}

B. Network Configuration
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The R1 company wants to hold a web search championship. There were n computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the i-th computer it was ai kilobits per second.

There will be k participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible.

The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least k of ncomputers had the same data transfer speed and the data transfer speed on these computers was as large as possible?

Input

The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of n integers: a1, a2, ..., an(16 ≤ ai ≤ 32768); number ai denotes the maximum data transfer speed on the i-th computer.

Output

Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.

Sample test(s)
input
3 2
40 20 30
output
30
input
6 4
100 20 40 20 50 50
output
40
Note

In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.


由于数据太太太太太!小。。。于是一个桶排序不就ok了。。。。


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;

int a[32868];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        int t;cin>>t;a[t]++;
    }
    for(int i=32768;i>=16;i--)
    {
        if(a[i]>=k)
        {
            cout<<i<<endl;
            break;
        }
        if(a[i])
        a[i-1]+=a[i];
    }
    return 0;
}

C. Pattern
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules.

In this task, a pattern will be a string consisting of small English letters and question marks ('?'). The question mark in the pattern is a metacharacter that denotes an arbitrary small letter of the English alphabet. We will assume that a string matches the pattern if we can transform the string into the pattern by replacing the question marks by the appropriate characters. For example, string aba matches patterns: ?????aa?aaba.

Programmers that work for the R1 company love puzzling each other (and themselves) with riddles. One of them is as follows: you are given n patterns of the same length, you need to find a pattern that contains as few question marks as possible, and intersects with each of the given patterns. Two patterns intersect if there is a string that matches both the first and the second pattern. Can you solve this riddle?

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of patterns. Next n lines contain the patterns.

It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does not exceed 105 characters.

Output

In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.

Sample test(s)
input
2
?ab
??b
output
xab
input
2
a
b
output
?
input
1
?a?b
output
cacb
Note

Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of other optimal answers, for example: aabbabcabdab and so on.


这题的数组貌似开不了辣么大,所以呢,想办法,我把所有字符全丢一个数组里边儿了,反正最多100000,就算遍历也不会艹时~~


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;

char s[100010],a[100010];
int main()
{
    int n;
    cin>>n;
    cin>>s;
    int ll=strlen(s),l=ll*n;
    strcpy(a,s);
    for(int i=ll;i<l;i++)
        cin>>a[i];
    for(int i=0;i<ll;i++)
    {
        int flag=0,ans=1;char w;
        for(int j=i;j<l;j+=ll)
        {
            if(a[j]!='?'&&!flag)
                flag=1,w=a[j];
            else if(a[j]!='?'&&flag)
            {
                if(a[j]!=w)
                {ans=0;break;}
            }
        }
        if(!flag)
            cout<<'z';
        else
        {
            if(ans)
                cout<<w;
            else cout<<'?';
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值