题目链接

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 <stdio.h>
#include <string.h>
#include <iostream> using namespace std ; char ch[] ; int main()
{
int n ,k ;
while(~scanf("%d %d",&n,&k))
{
scanf("%s",ch) ;
if(k == n)
{
printf("PRINT %c\n",ch[n-]) ;
for(int i = n- ; i >= ; i--)
{
printf("LEFT\n") ;
printf("PRINT %c\n",ch[i]) ;
}
}
else if(k == )
{
printf("PRINT %c\n",ch[]) ;
for(int i = ; i < n ; i++)
{
printf("RIGHT\n") ;
printf("PRINT %c\n",ch[i]) ;
}
}
else
{
if(n-k <= k-)
{
for(int i = k+ ; i <= n ; i++)
printf("RIGHT\n") ;
printf("PRINT %c\n",ch[n-]) ;
for(int i = n- ; i >= ; i --)
{
printf("LEFT\n") ;
printf("PRINT %c\n",ch[i]) ;
}
}
else
{
for(int i = ; i < k ; i++)
printf("LEFT\n") ;
printf("PRINT %c\n",ch[]) ;
for(int i = ; i < n ; i++)
{
printf("RIGHT\n") ;
printf("PRINT %c\n",ch[i]) ;
}
}
}
}
return ;
}

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 n computers 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.

题意 : 给你n个网速,大网速可以切成任意的比它小的网速,让你输出能得到的最大的k个网速是多大。

思路 : 其实就是求第k大的数是多少。

 //B
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm> using namespace std ; int a[] ; int main()
{
int n,k ;
while(~scanf("%d %d",&n,&k))
{
for(int i = ; i < n ; i++)
scanf("%d",&a[i]) ;
sort(a,a+n) ;
printf("%d\n",a[n-k]) ;
}
return ;
}

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: ???, ??a, a?a, aba.

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: aab, bab, cab, dab and so on.

题意 : 其实一开始我没怎么看懂题意,搜了题解才懂题意,就是给你n个长度相同的字符串,让你找一个能匹配所有字符串的尽量用较少的‘?’的字符串输出,因为问号可以看为随意的字母。

思路 :找每一列,如果都是问号的话就换成随意一个小写字母都行(我用的是a),如果这一列只有一个字母,那么就是这个字母,如果这一列不仅有问号还有别的英文字母而且这些英文字母都是一个,那还是换成这个字母,如果这一列有两个不同的字母,就只能用问号匹配了。

 //C
#include <stdio.h>
#include <string.h>
#include <iostream> using namespace std ; char ch[],sh[] ;
int flag[] ; int main()
{
int n ,len;
scanf("%d",&n) ;
for(int i = ; i < ; i++)
sh[i] = '?' ;
memset(flag,,sizeof(flag)) ;
for(int i = ; i < n ; i++)
{
scanf("%s",ch) ;
len = strlen(ch) ;
for(int j = ; j < len ; j++)
{
if( !flag[j] && sh[j] == '?')
sh[j] = ch[j] ;
else if(ch[j] == '?') continue ;
else if(sh[j] == ch[j])
{
continue ;
}
else if( !flag[j] && sh[j] != ch[j] && ch[j] != '?' && sh[j] != '?')
{
flag[j] = ;
sh[j] = '?' ;
}
}
// printf("*%c*\n",sh[len-1]) ;
}
for(int i = ; i < len ; i++)
{
if(flag[i] && sh[i] == '?')
printf("?") ;
else if(!flag[i] && sh[i] == '?')
printf("a") ;
else printf("%c",sh[i]) ;
}
return ;
}

D. Giving Awards

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

The employees of the R1 company often spend time together: they watch football, they go camping, they solve contests. So, it's no big deal that sometimes someone pays for someone else.

Today is the day of giving out money rewards. The R1 company CEO will invite employees into his office one by one, rewarding each one for the hard work this month. The CEO knows who owes money to whom. And he also understands that if he invites person x to his office for a reward, and then immediately invite person y, who has lent some money to person x, then they can meet. Of course, in such a situation, the joy of person x from his brand new money reward will be much less. Therefore, the R1 CEO decided to invite the staff in such an order that the described situation will not happen for any pair of employees invited one after another.

However, there are a lot of employees in the company, and the CEO doesn't have a lot of time. Therefore, the task has been assigned to you. Given the debt relationships between all the employees, determine in which order they should be invited to the office of the R1 company CEO, or determine that the described order does not exist.

Input

The first line contains space-separated integers n and m  — the number of employees in R1 and the number of debt relations. Each of the following m lines contains two space-separated integers aibi (1 ≤ ai, bi ≤ nai ≠ bi), these integers indicate that the person number ai owes money to a person a number bi. Assume that all the employees are numbered from 1 to n.

It is guaranteed that each pair of people pq is mentioned in the input data at most once. In particular, the input data will not contain pairs pq and qp simultaneously.

Output

Print -1 if the described order does not exist. Otherwise, print the permutation of n distinct integers. The first number should denote the number of the person who goes to the CEO office first, the second number denote the person who goes second and so on.

If there are multiple correct orders, you are allowed to print any of them.

Sample test(s)
input
2 1
1 2
output
2 1 
input
3 3
1 2
2 3
3 1
output

2 1 3

题意:老板要发工资,如果1欠了2的钱,那么发工资的时候,先叫1进去给他工资,然后再叫2进去的话,那1肯定就不会那么高兴了,所以老板发工资的时候要杜绝这种情况,让你输出一个合理的序列,如果不能就输出-1 .

思路 : 有了这个关系就可以看出来其实就是一个拓扑排序。
 //D
#include <stdio.h>
#include <string.h>
#include <vector>
#include <iostream> using namespace std ; bool vis[] ;
int a ;
int n,m ;
vector<int> v[] ; void DFS(int u)
{
if(vis[u]) return ;
vis[u] = true ;
for(int i = ; i < v[u].size() ; i++)
{
DFS(v[u][i]) ;
}
a++ ;
if(a == n)
printf("%d\n",u) ;
else printf("%d ",u) ;
}
int main()
{
int c,d ;
while(~scanf("%d %d",&n,&m))
{
memset(vis,false ,sizeof(vis)) ;
for(int i = ; i <= n ; i++)
v[i].clear() ;
while(m -- )
{
scanf("%d %d",&c,&d) ;
v[c].push_back(d) ;
}
a = ;
for(int i = ; i <= n ; i++)
{
if(!vis[i])
DFS(i) ;
}
}
return ;
}

E. E-mail Addresses

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day.

Today, the online news thundered with terrible information. The R1 database crashed and almost no data could be saved except for one big string. The developers assume that the string contains the letters of some users of the R1 mail. Recovering letters is a tedious mostly manual work. So before you start this process, it was decided to estimate the difficulty of recovering. Namely, we need to calculate the number of different substrings of the saved string that form correct e-mail addresses.

We assume that valid addresses are only the e-mail addresses which meet the following criteria:

  • the address should begin with a non-empty sequence of letters, numbers, characters '_', starting with a letter;
  • then must go character '@';
  • then must go a non-empty sequence of letters or numbers;
  • then must go character '.';
  • the address must end with a non-empty sequence of letters.

You got lucky again and the job was entrusted to you! Please note that the substring is several consecutive characters in a string. Two substrings, one consisting of the characters of the string with numbers l1, l1 + 1, l1 + 2, ..., r1 and the other one consisting of the characters of the string with numbers l2, l2 + 1, l2 + 2, ..., r2, are considered distinct if l1 ≠ l2 or r1 ≠ r2.

Input

The first and the only line contains the sequence of characters s1s2... sn (1 ≤ n ≤ 106) — the saved string. It is guaranteed that the given string contains only small English letters, digits and characters '.', '_', '@'.

Output

Print in a single line the number of substrings that are valid e-mail addresses.

Sample test(s)
input
gerald.agapov1991@gmail.com
output
18
input
x@x.x@x.x_e_@r1.com
output
8
input
a___@1.r
output
1
input
.asd123__..@
output
0
Note

In the first test case all the substrings that are correct e-mail addresses begin from one of the letters of the word agapov and end in one of the letters of the word com.

In the second test case note that the e-mail x@x.x is considered twice in the answer. Note that in this example the e-mail entries overlap inside the string.

题意 : 一个合格的电子邮箱必须满足一下条件:

  • 邮箱的前边必须是一个非空的序列,必须是字母数字或者是下划线,特别的,第一个字符必须是字母。
  • 然后接下来必须是字符@
  • 然后接下来必须是非空的字符串,由字母和数字组成。
  • 接下来必须是字符 .
  • 最后必须是非空的字符串由字母组成。

然后给你一个字符串让你求里边有多少个符合标准的电子邮箱。

思路 : 其实先找@前边的字符,找有多少个字母,然后找 . 后边有多少个字母相乘,这个我看的题解,自己写的时候指针都指乱了,由此看出自己和别人的差距啊!

 #include <stdio.h>
#include <string.h>
#include <iostream> using namespace std ; char ch[] ; int main()
{
scanf("%s",ch) ;
int len = strlen(ch) ;
long long cnt = ,a = ,ans = ;
for(int i = ; i < len ; i++)
{
if((ch[i] >= 'a' && ch[i] <= 'z')) cnt ++ ;
else if(ch[i] == '.') cnt = ;
else if(ch[i] == '@')
{
int j = ++ i ;
while(i < len && ((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= '' && ch[i] <= '')))
++ i ;
if(i != j && ch[i] == '.')
{
j = ++ i ;
a = ;
while(i < len && (ch[i] >= 'a' && ch[i] <= 'z'))
{
i++ ;
a++ ;
}
ans += a*cnt ;
}
i = j- ;
cnt = ;
}
}
printf("%I64d\n",ans) ;
return ;
}

Coder-Strike 2014 - Round 1(A~E)的更多相关文章

  1. SQLITE3 使用总结(3~5)(转)

    3 不使用回调查询数据库/ `- ^# T6 ?, F: H* m2 ~# ~上 面介绍的 sqlite3_exec 是使用回调来执行 select 操作.还有一个方法可以直接查询而不需要回调.但是, ...

  2. Neural Networks for Machine Learning by Geoffrey Hinton (1~2)

    机器学习能良好解决的问题 识别模式 识别异常 预測 大脑工作模式 人类有个神经元,每一个包括个权重,带宽要远好于工作站. 神经元的不同类型 Linear (线性)神经元  Binary thresho ...

  3. Linux中tty是什么(tty1~7)

    tty:终端设备的统称. tty一词源于Teletypes,或者teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西被键盘与显示器取代,所 ...

  4. BestCoder Round #85(ZOJ1569尚未验证)

    A题 子序列和啊,就要想到前缀和的差.这个转换一定要!记着!那么i到j的一段子序列和Sij%m ==  0就等价于(Sj-Si-1)%m == 0 了,那么什么意思呢?就是如果有两段前缀和%m的模是一 ...

  5. 2014 ICPC---Relief grain(树链剖分)

    原题链接 Problem Description The soil is cracking up because of the drought and the rabbit kingdom is fa ...

  6. POJ 2942 Knights of the Round Table (点双连通分量)

    题意:多个骑士要开会,3人及以上才能凑一桌,其中部分人已经互相讨厌,肯定不坐在同一桌的相邻位置,而且一桌只能奇数个人才能开台.给出多个人的互相讨厌图,要求多少人开不成会(注:会议不要求同时进行,一个人 ...

  7. BestCoder Round #65 (ZYB's Game)

    ZYB's Game Accepts: 672 Submissions: 1207 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...

  8. Codeforces Global Round 1D(DP,思维)

    #include<bits/stdc++.h>using namespace std;int dp[1000007][7][7];int cnt[1000007];int main(){  ...

  9. POJ3252 Round Numbers(不重复全排列)

    题目问区间有多少个数字的二进制0的个数大于等于1的个数. 用数学方法求出0到n区间的合法个数,然后用类似数位DP的统计思想. 我大概是这么求的,确定前缀的0和1,然后后面就是若干个0和若干个1的不重复 ...

随机推荐

  1. android application类的用法

    android application类的用法 Application是android系统Framework提供的一个组件,它是单例模式(singleton),即每个应用只有一个实例,用来存储系统的一 ...

  2. 第十一篇、RxSwift

    三. 什么是函数式编程? 什么是函数式编程呢? 函数式编程其实是一种编程思想, 代码写出来只是它的表现形式. 在面向对象的编程思想中, 我们将要解决的一个个问题, 抽象成一个个类, 通过给类定义属性和 ...

  3. 使用Playground编写第一个Swift程序

    从控制台输出“HelloWorld”是我学习C语言的第一步,也是我人生中非常重要的一步.多年后的今天,我仍希望以HelloWorld作为第一步,与大家共同开启一个神奇.瑰丽的世界——Swift编程. ...

  4. vJine 第三波 之 Lua 来袭 vJine.Lua

    vJine.Lua vJine.Lua是Lua语言的C#封装库,可实现通过C#直接运行Lua脚本并与Lua脚本交互的功能. 1. 授权: MPL2.0 相关资源: nuget:(https://www ...

  5. java SimpleDateFormat非线程安全测试

    public class MyThread extends Thread { private SimpleDateFormat sdf; private String dateString; publ ...

  6. 一个简单的CS系统打包过程图文版

    一个简单的CS系统打包过程图文版 1.     打包内容 1.1.  此次打包的要求和特点 主工程是一个CS系统: 此CS系统运行的先决条件是要有.Net Framework 3.5: 主工程安装完成 ...

  7. 04_例子讲解:rlViewDemo.exe

    参考资料:http://www.roboticslibrary.org/tutorials/first-steps-windows 使用rlViewDemo对应的快捷方式启动程序,可以看到如下界面: ...

  8. echo & print

    在实际使用中, print 和 echo 两者的功能几乎是完全一样.可以这么说,凡是有一个可以使用的地方,另一个也可以使用.但是,两者之间也还是一个非常重要的区别:在 echo 函数中,可以同时输出多 ...

  9. C# Json数据反序列化为Dictionary并根据关键字获取指定值

    Json数据: { "dataSet": { "header": { "returnCode": "0", " ...

  10. 使用c#检测文件正在被那个进程占用

    要检测文件被那个进程占用,需要使用微软提供的工具Handle.exe,这里有微软提供的下载 我们可以在c#中调用Handle.exe 来检测到底哪个进程占用了文件 string fileName = ...