2018SDIBT_国庆个人第七场
A - Complete the Word(暴力)
Description
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.
Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
Input
The first and only line of the input contains a single string s (1 ≤ |s| ≤ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
Output
If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print - 1 in the only line.
Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters.
If there are multiple solutions, you may print any of them.
Sample Input
ABC??FGHIJK???OPQR?TUVWXY?
ABCDEFGHIJKLMNOPQRZTUVWXYS
WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO
-1
??????????????????????????
MNBVCXZLKJHGFDSAQPWOEIRUYT
AABCDEFGHIJKLMNOPQRSTUVW??M
-1
Hint
In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.
In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is - 1.
In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
题意:给你一个字符串,字符串由26个大写字母和?组成,可以将?替换成任何大写字母,问有没有子串只有26个不同的大写字母,有则输出原串,且?被替换掉,否则输出-1
分析:暴力即可,遍历所有的子串,如果某个子串中的大写字母出现了一次以上,则遍历下一个子串,如果某个子串满足条件,替换子串中的?替换成相应的大写字母,并且将原串中其他的?替换成大写字母
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
char s[];
while(~scanf("%s",s))
{
int len = strlen(s);
int a[],i;//a标记子串中出现的大写字母
if (len < ) {
printf("-1\n");
continue;
}//如果所给的原串的长度小于26直接输出-1
for (i = ; i < len-; i++)
{
memset(a,,sizeof(a));
int flag = ;
for (int j = i; j <= i+; j++)
{
if (s[j] == '?')
continue;//当碰到?时继续遍历
if (a[s[j]-] == ) {
a[s[j]-] = ;
} else {//当子串中的某个大写字母出现了一次以上,遍历下一个子串
flag = ;
break;
}
}
if(flag == )
continue;
int b[]={};//标记没有出现的字符
int k=;
for (int j = ; j < ; j++)
{
if(a[j] == )
b[k++] = j;
}
k = ;
for (int j = i; j <= i+; j++)
{
if (s[j] == '?') s[j] = b[k++] + ;//将子串中的?替换成相应的大写字母
}
for (int j = ; j < len; j++)
{
if (s[j] == '?') {
printf("A");//将原串中其他的?用大写字母输出
} else {
printf("%c",s[j]);
}
}
printf("\n");
break;
}
if(i == len-)
printf("-1\n")//没有遍历到符合条件的子串 则输出-1;
}
return ;
}
cutecode
C - Anatoly and Cockroaches
Description
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color.
Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of cockroaches.
The second line contains a string of length n, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively.
Output
Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate.
Sample Input
5
rbbrr
1
5
bbbbb
2
3
rbr
0
Hint
In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer is 0.
题意:给你一个字符串只由‘r'和'b'组成,你可以对字符进行改变和交换操作,每个操作花费1,问如何使这个字符串变成交替的,并且花费最少
分析:只可能有rbrbrbr 和 brbrbrb两种类型,让字符串与这两种类型的比较对照
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
int n;
char s[];
while(~scanf("%d",&n))
{
scanf("%s",s);
int sum1 = , sum2 = ;
for (int i = ; i < n; i++)
{
if (i % == ) {
if (s[i] != 'r')
sum1++;
} else {
if (s[i] != 'b')
sum2++;
}
}//比较对照
int ans=;
ans = abs(sum2-sum1) + min(sum1,sum2);//min(sum1,sum2)让不在位置上的r,b进行交换,ans(sum1,sum2)表示剩余的没有交换的r或b
sum1 = , sum2 = ;
for (int i = ; i < n; i++)
{
if (i % == ){
if (s[i] != 'b')
sum1++;
} else {
if (s[i] != 'r')
sum2++;
}
}//两种类型的字符串
ans = min(ans,abs(sum2-sum1) + min(sum1,sum2));
printf("%d\n",ans);
}
return ;
}
可爱的代码
D - Efim and Strange Grade
Description
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after the decimal point (also, he can ask to round to the nearest integer).
There are t seconds left till the end of the break, so Efim has to act fast. Help him find what is the maximum grade he can get in no more than t seconds. Note, that he can choose to not use all t seconds. Moreover, he can even choose to not round the grade at all.
In this problem, classic rounding rules are used: while rounding number to the n-th digit one has to take a look at the digit n + 1. If it is less than 5 than the n-th digit remain unchanged while all subsequent digits are replaced with 0. Otherwise, if the n + 1 digit is greater or equal to 5, the digit at the position n is increased by 1 (this might also change some other digits, if this one was equal to 9) and all subsequent digits are replaced with 0. At the end, all trailing zeroes are thrown away.
For example, if the number 1.14 is rounded to the first decimal place, the result is 1.1, while if we round 1.5 to the nearest integer, the result is 2. Rounding number 1.299996121 in the fifth decimal place will result in number 1.3.
Input
The first line of the input contains two integers n and t (1 ≤ n ≤ 200 000, 1 ≤ t ≤ 109) — the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the decimal points, and it's representation doesn't finish with 0.
Output
Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes.
Sample Input
6 1
10.245
10.25
6 2
10.245
10.3
3 100
9.2
9.2
Hint
In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all.
E - Vitya in the Countryside
Description
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains n integers ai (0 ≤ ai ≤ 15) — Vitya's records.
It's guaranteed that the input data is consistent.
Output
If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
Sample Input
5
3 4 5 6 7
UP
7
12 13 14 15 14 13 12
DOWN
1
8
-1
Hint
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.
题意:vitya在记录每晚的月亮,每天晚上可见部分的月亮的大小有着30天的周期,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1。
1的后面紧接着的是0。vitya一共要观察n天,她想知道第n+1天的月亮是上升还是下降,给出这n天里月亮的大小。
分析:如果n=1
当a[n]=0时,第n+1天一定是上升
当a[n]=15时,第n+1天一定是下降
其余情况不确定
当n>1时
当a[n]>a[n-1] 如果a[n]=15,那么第n+1天一定是下降;其余情况,一定是上升
当a[n]<a[n-1] 如果a[n]=0,那么第n+1天一定是上升;其余情况,一定是下降。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
int main()
{
int n,a[];
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
if(n==)
{
if(a[n]==)
printf("UP\n");
else if(a[n]==)
printf("DOWN\n");
else
printf("-1\n");
}
else
{
if(a[n]>a[n-])
{
if(a[n]==)
printf("DOWN\n");
else
printf("UP\n");
}
else if(a[n]<a[n-])
{
if(a[n]==)
printf("UP\n");
else
printf("DOWN\n");
}
else
{
printf("-1\n");
}
}
}
return ;
}
可爱的代码
2018SDIBT_国庆个人第七场的更多相关文章
- 2018SDIBT_国庆个人第六场
A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...
- 2018SDIBT_国庆个人第五场
A - ACodeForces 1060A Description Let's call a string a phone number if it has length 11 and fits th ...
- 2018SDIBT_国庆个人第四场
A - A 这题很巧妙啊,前两天刚好做过,而且就在博客里 Little C Loves 3 I time limit per test 1 second memory limit per test ...
- 2018SDIBT_国庆个人第三场
A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai peo ...
- 2018SDIBT_国庆个人第二场
A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...
- 2018SDIBT_国庆个人第一场
A - Turn the Rectangles CodeForces - 1008B There are nn rectangles in a row. You can either turn eac ...
- HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...
- URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...
- hdu4940 Destroy Transportation system(2014多校联合第七场)
题意很容易转化到这样的问题:在一个强连通的有向图D中是否存在这样的集合划分S + T = D,从S到T集合的边权大于从T到S集合的边权. 即D(i, j) > B(j, i) + D(j, i ...
随机推荐
- Java学习笔记43(Spring的jdbc模板)
在之前的学习中,我们执行sql语句,需要频繁的开流,关流比较麻烦,为了更加的简化代码,我们使用Spring 的jdbc模板jdbcTemplate来简化我们的代码量:需要导入的包有: 我们在之前的dr ...
- Ubuntu Server 16.04设置WiFi
wifi :http://www.cnblogs.com/joeyupdo/p/3350463.html http://blog.csdn.net/meic51/article/details/173 ...
- git全局忽略文件
mac系统如何显示和隐藏文件 创建 ~/.gitignore_global .DS_Store __pycache__/ 配置选项 git config --global core.excludesf ...
- matplotlib画sin(x)和cos(x)/2
import matplotlib.pyplot as mp 1. 基本的绘图 mp.plot(水平坐标, 垂直坐标, linestyle=线型, linewidth=线宽, color=颜色, .. ...
- Lua IDE工具-Intellij IDEA+lua插件配置教程(Chianr出品)
Lua 编译工具IDE-Intellij IDEA 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Ch ...
- switch留个爪,之后还需要再研究下
public class SwitchDemo { public static void main (String [] args) { for(int i = 0; i < 10; i++) ...
- Ubuntu16.04中pip无法更新升级,采用源码方式安装
1.从pip官网下载最新版 https://pypi.org/project/pip/#files 2.ubuntu中创建文件位置,我的放在一下路径,之后进行解压 3.解压后进入pip的文件夹,在执行 ...
- 第二节《Git暂存区》
在上一节中我们的demo版本库经历了一次提交,我们可以使用git og --stat查看一下提交日志. [root@git demo]# git log --statcommit 986a1bd458 ...
- python 连接 oracle 统计指定表格所有字段的缺失值数
python连接oracle -- qlalchemy import cx_Oracle as co import pandas as pd from sqlalchemy import crea ...
- tomcat 端口修改和内存配置
端口号修改参考:https://jingyan.baidu.com/article/adc815139b12def722bf7377.html Tomcat内存溢出(windows) java.lan ...