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

Input
ABC??FGHIJK???OPQR?TUVWXY?
Output
ABCDEFGHIJKLMNOPQRZTUVWXYS
Input
WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO
Output
-1
Input
??????????????????????????
Output
MNBVCXZLKJHGFDSAQPWOEIRUYT
Input
AABCDEFGHIJKLMNOPQRSTUVW??M
Output
-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

Input
5
rbbrr
Output
1
Input
5
bbbbb
Output
2
Input
3
rbr
Output
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

Input
6 1
10.245
Output
10.25
Input
6 2
10.245
Output
10.3
Input
3 100
9.2
Output
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

Input
5
3 4 5 6 7
Output
UP
Input
7
12 13 14 15 14 13 12
Output
DOWN
Input
1
8
Output
-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_国庆个人第七场的更多相关文章

  1. 2018SDIBT_国庆个人第六场

    A - A codeforces 714A Description Today an outstanding event is going to happen in the forest — hedg ...

  2. 2018SDIBT_国庆个人第五场

    A - ACodeForces 1060A Description Let's call a string a phone number if it has length 11 and fits th ...

  3. 2018SDIBT_国庆个人第四场

    A - A  这题很巧妙啊,前两天刚好做过,而且就在博客里  Little C Loves 3 I time limit per test 1 second memory limit per test ...

  4. 2018SDIBT_国庆个人第三场

    A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai peo ...

  5. 2018SDIBT_国庆个人第二场

    A.codeforces1038A You are given a string ss of length nn, which consists only of the first kk letter ...

  6. 2018SDIBT_国庆个人第一场

    A - Turn the Rectangles CodeForces - 1008B There are nn rectangles in a row. You can either turn eac ...

  7. HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...

  8. URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场

    比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...

  9. hdu4940 Destroy Transportation system(2014多校联合第七场)

    题意很容易转化到这样的问题:在一个强连通的有向图D中是否存在这样的集合划分S + T = D,从S到T集合的边权大于从T到S集合的边权. 即D(i, j)  > B(j, i) + D(j, i ...

随机推荐

  1. C# 时间戳 整理

    以前遇到时间戳,都是那公共类里面的方法来用.未曾理解过它的原理. C# 时间类型枚举     分为local.utc.以及Unspecified local:当地时间,例如我们所在的东八区,所采用的北 ...

  2. VS2010添加虚拟机发布的WebService引用

    首先,WebServer已在虚拟机中完成发布.在网页中浏览可以看到如下所示内容 需要注意的是在发布时要给网站设置IP地址.如果在添加网站时没有设置,之后可以在网站绑定中进行修改.步骤如下: 1.选中网 ...

  3. 【转】python两个 list 获取交集,并集,差集的方法

    1. 获取两个list 的交集: #方法一: a=[2,3,4,5] b=[2,5,8] tmp = [val for val in a if val in b] print tmp #[2, 5] ...

  4. CSVN配置自动备份策略

    在浏览器中登录CSVN管理页面,登录地址就是ip:3343,版本库->backup schedule ,选择type of job(备份类型),when to run(备份频率和时间),numb ...

  5. MySQL Execution Plan--NOT IN查询

    在某系统中想使用NOT IN子查询进行数据过滤,SQL为: SELECT * FROM TB001 AS T1 DAY) AND T1.BATCH_NO NOT IN(SELECT BATCH_NO ...

  6. create table 推荐规则

    create table 推荐规则: 所有列都设置NOT NULL,都写备注(comment) 除主键外,所有列都设置默认值(default)

  7. java-Redis集合

    引用包:jedis-3.0.1.jar.commons-pool2-2.6.0.jar 一.从Redis集合中实时获取数据: 连接Redis import redis.clients.jedis.Je ...

  8. [转]马上2018年了,该不该下定决心转型AI呢

    转自:http://blog.csdn.net/eNohtZvQiJxo00aTz3y8/article/details/78941013 2017年,AI再一次迈向风口,但我们如何判断未来走向?应不 ...

  9. Inheritance setUp() and tearDown() methods from Classsetup() and Classteardown

      I have a general test class in my nosetests suit and some sub-classes, inheriting from it. The con ...

  10. Spring复习

    第一天 IOC:控制反转,对象的创建权交给Spring DI:依赖注入,前提必须有IOC的环境,Spring管理这个类的时候将类的依赖的属性注入(设置)进来. 包括集合的注入 ClassPathXml ...