Coder-Strike 2014 - Round 1(A~E)
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!
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: '.', '!', ',', '?'.
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.
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 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?
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.
Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.
3 2
40 20 30
30
6 4
100 20 40 20 50 50
40
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?
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.
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.
2
?ab
??b
xab
2
a
b
?
1
?a?b
cacb
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.
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 ai, bi (1 ≤ ai, bi ≤ n; ai ≠ 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 p, q is mentioned in the input data at most once. In particular, the input data will not contain pairs p, q and q, p simultaneously.
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.
2 1
1 2
2 1
3 3
1 2
2 3
3 1
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.
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 '.', '_', '@'.
Print in a single line the number of substrings that are valid e-mail addresses.
gerald.agapov1991@gmail.com
18
x@x.x@x.x_e_@r1.com
8
a___@1.r
1
.asd123__..@
0
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)的更多相关文章
- SQLITE3 使用总结(3~5)(转)
3 不使用回调查询数据库/ `- ^# T6 ?, F: H* m2 ~# ~上 面介绍的 sqlite3_exec 是使用回调来执行 select 操作.还有一个方法可以直接查询而不需要回调.但是, ...
- Neural Networks for Machine Learning by Geoffrey Hinton (1~2)
机器学习能良好解决的问题 识别模式 识别异常 预測 大脑工作模式 人类有个神经元,每一个包括个权重,带宽要远好于工作站. 神经元的不同类型 Linear (线性)神经元 Binary thresho ...
- Linux中tty是什么(tty1~7)
tty:终端设备的统称. tty一词源于Teletypes,或者teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西被键盘与显示器取代,所 ...
- BestCoder Round #85(ZOJ1569尚未验证)
A题 子序列和啊,就要想到前缀和的差.这个转换一定要!记着!那么i到j的一段子序列和Sij%m == 0就等价于(Sj-Si-1)%m == 0 了,那么什么意思呢?就是如果有两段前缀和%m的模是一 ...
- 2014 ICPC---Relief grain(树链剖分)
原题链接 Problem Description The soil is cracking up because of the drought and the rabbit kingdom is fa ...
- POJ 2942 Knights of the Round Table (点双连通分量)
题意:多个骑士要开会,3人及以上才能凑一桌,其中部分人已经互相讨厌,肯定不坐在同一桌的相邻位置,而且一桌只能奇数个人才能开台.给出多个人的互相讨厌图,要求多少人开不成会(注:会议不要求同时进行,一个人 ...
- BestCoder Round #65 (ZYB's Game)
ZYB's Game Accepts: 672 Submissions: 1207 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- Codeforces Global Round 1D(DP,思维)
#include<bits/stdc++.h>using namespace std;int dp[1000007][7][7];int cnt[1000007];int main(){ ...
- POJ3252 Round Numbers(不重复全排列)
题目问区间有多少个数字的二进制0的个数大于等于1的个数. 用数学方法求出0到n区间的合法个数,然后用类似数位DP的统计思想. 我大概是这么求的,确定前缀的0和1,然后后面就是若干个0和若干个1的不重复 ...
随机推荐
- 【转】用capability 特征加强Linux系统安全
用capability 特征加强Linux系统安全 摘要:传统UNIX系统的访问控制模型非常简单——普通用户对超级用户.在这种模型中,一个进程或者帐户要么只有很小的权限,要么具有全部的系统权限.显然, ...
- oracle开启audit(审计)
1.查看审计功能是否开启(本机已经开启,如果audit_sys_operations值为FALSE就是没开审计) [sql] view plaincopyprint? SQL> CONN /AS ...
- 使用Emmet(前身Zen Coding)加速Web前端开发
Emmet插件以前被称作为Zen Coding,是一个文本编辑器的插件,它可以帮助您快速编写HTML和CSS代码,从而加速Web前端开发.早在2009年,Sergey Chikuyonok写过一篇文章 ...
- iOS开发——时间格式类
目前只实现了三个类方法, 第一个获取当前时间,以字符创的形式返回,例如"201606161532" 第二个以当前时间与给定时间的时间差(秒) 第三个以当前时间与给定时间的时间差(分 ...
- c++中"endl"和"\n"的区别
看C++视频教程-范磊主讲(2.91G)视频搞懂了c++中"endl"和"\n"的区别. 学习笔记如下: c++中 换行符"endl"该符号 ...
- 使用python读写windows剪切板
import win32clipboard as w import win32con base_addr = 0x8e00000 buffer_len = 0x123 def getText(): w ...
- 在Apache中开启虚拟主机
最近在自学LAMP,在Apache中尝试着开启虚拟主机的时候,遇到了挺多麻烦的,这里也顺便总结一下,在Apache中开启虚拟主机的时候,主要有下面几个步骤: 1.新建一个文件夹作为虚拟主机,用来存储网 ...
- rsync命令(同步/备份数据)
rsync命令rsync命令是一个远程数据同步工具,可通过 lam/wan快速同步多台主机间的文件.rsync使用所谓的 "rsync算法"来使用本地和远程两个主机之间的文件达到同 ...
- 【Android】Android SDK在线更新镜像服务器
Android SDK在线更新镜像服务器 中国科学院开源协会镜像站地址: IPV4/IPV6: http://mirrors.opencas.cn 端口:80 IPV4/IPV6: http://mi ...
- jquery 点击查看,收起特效
<div class="all"> <p><a href="javascript:;" id="onvk"&g ...