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

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

分析:暴力即可,遍历所有的子串,如果某个子串中的大写字母出现了一次以上,则遍历下一个子串,如果某个子串满足条件,替换子串中的?替换成相应的大写字母,并且将原串中其他的?替换成大写字母

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 using namespace std;
 5 int main()
 6 {
 7     char s[50005];
 8     while(~scanf("%s",s))
 9     {
10         int len = strlen(s);
11         int a[26],i;//a标记子串中出现的大写字母
12         if (len < 26) {
13             printf("-1\n");
14             continue;
15         }//如果所给的原串的长度小于26直接输出-1
16         for (i = 0; i < len-25; i++)
17         {
18             memset(a,0,sizeof(a));
19             int flag = 0;
20             for (int j = i; j <= i+25; j++)
21             {
22                 if (s[j] == ‘?‘)
23                     continue;//当碰到?时继续遍历
24                 if (a[s[j]-65] == 0) {
25                     a[s[j]-65] = 1;
26                 } else {//当子串中的某个大写字母出现了一次以上,遍历下一个子串
27                     flag = 1;
28                     break;
29                 }
30             }
31             if(flag == 1)
32                 continue;
33             int b[26]={0};//标记没有出现的字符
34             int k=0;
35             for (int j = 0; j < 26; j++)
36             {
37                 if(a[j] == 0)
38                     b[k++] = j;
39             }
40             k = 0;
41             for (int j = i; j <= i+25; j++)
42             {
43                 if (s[j] == ‘?‘) s[j] = b[k++] + 65;//将子串中的?替换成相应的大写字母
44             }
45             for (int j = 0; j < len; j++)
46             {
47                 if (s[j] == ‘?‘) {
48                     printf("A");//将原串中其他的?用大写字母输出
49                 } else {
50                     printf("%c",s[j]);
51                 }
52             }
53             printf("\n");
54             break;
55         }
56         if(i == len-25)
57             printf("-1\n")//没有遍历到符合条件的子串 则输出-1;
58     }
59     return 0;
60 }

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

5rbbrr

Output

1

Input

5bbbbb

Output

2

Input

3rbr

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[100005];
    while(~scanf("%d",&n))
    {
        scanf("%s",s);
        int sum1 = 0, sum2 = 0;
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0) {
                if (s[i] != ‘r‘)
                    sum1++;
            } else {
                if (s[i] != ‘b‘)
                    sum2++;
            }
        }//比较对照
        int ans=0;
        ans = abs(sum2-sum1) + min(sum1,sum2);//min(sum1,sum2)让不在位置上的r,b进行交换,ans(sum1,sum2)表示剩余的没有交换的r或b
        sum1 = 0, sum2 = 0;
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0){
                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 0;
}

可爱的代码

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 110.245

Output

10.25

Input

6 210.245

Output

10.3

Input

3 1009.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

53 4 5 6 7

Output

UP

Input

712 13 14 15 14 13 12

Output

DOWN

Input

18

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天一定是上升;其余情况,一定是下降。

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<map>
 7 using namespace std;
 8 int main()
 9 {
10     int n,a[100];
11     while(~scanf("%d",&n))
12     {
13         for(int i=1;i<=n;i++)
14             scanf("%d",&a[i]);
15         if(n==1)
16         {
17             if(a[n]==0)
18             printf("UP\n");
19             else if(a[n]==15)
20                 printf("DOWN\n");
21             else
22             printf("-1\n");
23         }
24         else
25         {
26             if(a[n]>a[n-1])
27             {
28                 if(a[n]==15)
29                     printf("DOWN\n");
30                 else
31                     printf("UP\n");
32             }
33             else if(a[n]<a[n-1])
34             {
35                 if(a[n]==0)
36                     printf("UP\n");
37                 else
38                     printf("DOWN\n");
39             }
40             else
41             {
42                 printf("-1\n");
43             }
44         }
45     }
46     return 0;
47 }

可爱的代码

原文地址:https://www.cnblogs.com/LLLAIH/p/9768198.html

时间: 2024-07-31 10:22:26

2018SDIBT_国庆个人第七场的相关文章

2018SDIBT_国庆个人第三场

A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Another mm people are coming to the park and each of them is going to have a seat on some bench out of n

2018SDIBT_国庆个人第四场

A - A  这题很巧妙啊,前两天刚好做过,而且就在博客里 Little C Loves 3 I time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little C loves number «3» very much. He loves all things about it. Now he has a positive int

2018SDIBT_国庆个人第五场

A - ACodeForces 1060A Description Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit. For example, "80123456789" and "80000000000" are ph

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分相同,第一部分与第二部分对称. 现在给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法,求出以第i个点为中心的回文串长度,记录到数组p中 要满足题目所要求的内容,需要使得两个相邻的回文串,共享中间的一部分,也就是说,左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也是一样. 因为我们已经记录下来以

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&amp;#39;s problem(manacher+二分/枚举)

pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法.求出以第i个点为中心的回文串长度.记录到数组p中 要满足题目所要求的内容.须要使得两个相邻的回文串,共享中间的一部分,也就是说.左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也

近期这七场IT技术大会你会选哪场?

时间很快,油菜花又要等到明年了.而现在会议行业也进入了旺季,面对众多的会议,你是否还在观望?今天,活动家为大家整理了近期的七场IT技术大会,一起来斟酌下吧~ PS:由时间近到远排序,小伙伴们自行斟酌~ 一.SDCC系列活动 2017上海站 运维开发+数据库+应用架构实战峰会 由CSDN重磅打造的三场峰会,秉承干货实料(案例)的内容原则,这三 场峰会将邀请业内顶尖的架构师和技术专家,共同探讨运维工具研发与实践.运维自动化系统的构建.大数据与运维.云上的运维案例分析.虚拟化技术.应用性能检测与管理.

2014多校第七场1005 || HDU 4939 Stupid Tower Defense (DP)

题目链接 题意 :长度n单位,从头走到尾,经过每个单位长度需要花费t秒,有三种塔: 红塔 :经过该塔所在单位时,每秒会受到x点伤害. 绿塔 : 经过该塔所在单位之后的每个单位长度时每秒都会经受y点伤害. 蓝塔 : 经过该塔所在单位之后,再走每个单位长度的时候时间会变成t+z. 思路 : 官方题解 : 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #define LL long long

多校第七场 DP+map模拟

HDU 4939 Stupid Tower Defense DP 推一下. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include<queue> #include<stack> #include<vector> #include<ctype.h> #include<

2014多校联合-第七场

1005: ( Stupid Tower Defense ) 由题意我们很明显可以知道,红色的塔放在最后面是最优的. 假如前i个塔,放j个绿塔,i-j个蓝塔.那么无论前i个塔的顺序怎么放,对后面的塔造成的影响是完全相同的. dp[i][j]:前i个塔,放j个绿塔,能获得的最大价值. dp[i][j]=max(dp[i-1][j-1]+当前塔放绿塔获得的能量值,dp[i-1][j]+当前塔放蓝塔获得的能量值): #include <iostream> #include<stdio.h>