国庆个人赛——NO.7

1、

Codeforces-716B  Complete the Word

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.

题意:

这个题意就比较难懂了,做题的时候就在瞎猜题意,结果一直WA

正确题意是:

给一个字符串,由大写英文字母和‘ ?’组成,‘ ?’可以变成任意的大写字母

去找字符串中是不是存在一个连续的子串,满足长度是26,包含‘A'-'Z'所有的字母,这些字母有且仅出现一次

思路:

从前往后暴力搜索满足条件的即可,依次搜26个字母。

当然如果总长度小于26肯定输出-1,最后处理好?的填充处理就行了

题目要求的是输出全部字符串!不是满足条件的子串!!

需要注意:

1、长度必须大于等于26,小于26不满足题意

2、一个连续的子串,必须包含‘A'-'Z'所有的字母,将‘ ?’变成这一个子串中没出现的字母

3、除满足题意的这一个子串外,其余包含‘ ?’的变成大写字母的任意字母,为了方便起见,将其变成‘A'

CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int vis[50000+10];
int b[50000+10];
int main()
{
    char s[50000+10];
    scanf("%s",s);

    int xx;
    int flag=0;

    int sum=0;

    if(strlen(s)<26) // 长度小于 26是不满足题意的
        printf("-1\n");
    else
    {
        xx=-1;
        int i;
        for(i=0; i<strlen(s)-25; i++)
        {
            memset(vis,0);
            flag=0;


            for(int j=i; j<26+i; j++)
            {
                if(vis[s[j]]==0)
                {
                    if(s[j]>='A'&&s[j]<='Z')
                        vis[s[j]]=1;
                }
                else
                {
                    flag=1; // 如果出现某一个字母出现了不止一次,就输出 -1
                    break;
                }
            }
            if(flag==1)
                continue;
            else
            {
                xx=i; // 记录下来满足题意的子串的第一个位置
                break;
            }
        }

      // 如果出现一个字母不仅出现一次或者是找到字符串末尾都没有找到符合题意的

        if(flag==1||i==strlen(s)-25) 
            printf("-1\n");

        else
        {
            for(int j=xx; j<xx+26; j++) //对符合题意的子串进行改变
            {
                if(s[j]=='?')
                {
           
                    for(char k='A'; k<='Z'; k++)
                    {
                        if(vis[k]==0)
                        {
                            s[j]=k;

                            vis[k]=1;
                            break; // 对当前问号找到一个就停止即可
                        }
                    }
                }
            }

        

            for(int j=0; j<strlen(s); j++)
            {
                if(j>=xx&&j<=xx+25) //对除满足题意得子串之外的字符进行改变
                    continue;
                if(s[j]=='?')
                    s[j]='A';
            }
            printf("%s\n",s);
        }
    }

}

2、

3、

Codeforces-719B  Anatoly and Cockroaches

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 的序列,要求把它变成 r和b 交错出现的"有序"序列,

现在有两种操作:①交换任意位置的2个字符;②选择一个位置的字符把它变成另一个字符,问至少要经过几次操作才能变成"有序"序列

思路:

不管怎样变化,最后的序列一定是 rbrb 或者 brbr  样式的

先判断转化成 rbrb...此种形式的次数

奇数位置上不是r——r++,偶数位置上不是b——b++

如果r==0&&b==n/2,说明全是r的情形,那么输出n/ 2,(需要将n/2个换成b)

否则的话,改变的次数是ans=max(b,r)

再去判断 brbr... 这种形式的,同上,输出ans1=max(b,r)

最后输出 min(ans,ans1)(有的字符串虽然是r开头,但是他换成b开头的需要的次数更少,比如 rbrbr,只需要一次即可,所以需要比较一下求一个最小的)

CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

char s[100000+10];

int main()
{
    int n;
    scanf("%d",&n);
    getchar();
    scanf("%s",s);

    //cout<<strlen(s)<<endl;

    int b=0,r=0,ans=0,ans1=0,bb=0,rr=0;

    for(int i=0; i<n; i++)
    {
        if(s[i]!='b'&&i%2)
            b++;
        if(s[i]!='r'&&i%2==0)
            r++;
    }

    for(int i=0; i<n; i++)
    {
        if(s[i]!='b'&&i%2==0)
            bb++;
        if(s[i]!='r'&&i%2)
            rr++;
    }
    if(r==0&&b==n/2||bb==0&&rr==n/2)
        printf("%d\n",n/2);
    else
    {
        ans=max(b,r);
        ans1=max(bb,rr);
        printf("%d\n",min(ans,ans1));
    }


}

5、

Codeforces-719A Vitya in the Countryside

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.

题意:给定n个时间,是一个具有上升或者下降趋势的时间点,判断n+1个时间点是上升还是下降

思路:

题目是已经给好了月亮上升下降的循环周期,直接对给定的这个周期进行判定(不知道第一次为什么没看懂,唉)

循环周期是:

 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的话,下一个时间点是上升,如果最后一个是15的话,下一个时间点是下降

2、一个的时候,特殊判断是不是0或者15,否则输出不确定

3、其余的情况,比较a[n-1] 与 a[n-2]的大小即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

int a[100+10];

int main()
{
    int n;
    scanf("%d",&n);

    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);

    if(n==1)
    {
        if(a[0]==0)
            printf("UP\n");
        else if(a[0]==15)
            printf("DOWN\n");
        else
            printf("-1\n");
    }

    else
    {
        if(a[n-1]==0){
            printf("UP\n");
            return 0;
        }
        if(a[n-1]==15)
        {
            printf("DOWN\n");
            return 0;
        }

        if(a[n-1]>a[n-2])
            printf("UP\n");
        if(a[n-1]<a[n-2])
            printf("DOWN\n");
    }
}

猜你喜欢

转载自blog.csdn.net/JKdd123456/article/details/82972783