2018国庆第七场个人赛

版权声明:转载时 别忘了注明出处 https://blog.csdn.net/ZCY19990813/article/details/82958096

codeforces 719A

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

Sample Output

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.

看是递增的还是递减的,注意几种情况 

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <deque>
#include <set>
using namespace std;
typedef long long ll;
#define MAX 0x3f3f3f
map<ll,ll> M;
set<ll>s;
ll a[1110];
int main()
{
    ll n,i,sum;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    if(n==1)
    {
        if(a[0]==15)
            cout<<"DOWN"<<endl;
        else
        if(a[0]==0)
            cout<<"UP"<<endl;
        else
            cout<<"-1"<<endl;
    }

    else
    {
        if(a[n-2]==1&&a[n-1]==0)
            cout<<"UP"<<endl;
        else
        if(a[n-1]==15&&a[n-2]==14)
            cout<<"DOWN"<<endl;
        else
        {
            if(a[n-2]<a[n-1])
                cout<<"UP"<<endl;
            else
            if(a[n-2]>a[n-1])
               cout<<"DOWN"<<endl;
            else
                cout<<"-1"<<endl;
        }
    }
    return 0;
}

 

CodeForces 719B

 

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

给你一个由'r','b'组成的字符串,你可以进行两种操作:(1)把任意两个位置的字母互换;(2)把任意一个位置的r变成b,或b变成r。
输入一个字符串,问至少变几次才能成为r,b交错的序列?(rbrbrb….或者brbrbr…都行)

题目分析:
这是一个贪心策略,不过我一开始没想到。
分别考虑两种最终结果,计算字符串与目标串中r错位和b错位的个数(即目标为b,但实际为r和目标为r和实际为b),设为x1,x2,则要想把该字符串变成目标字符串,需要操作的次数为max(x1,x2)

.
(想想为什么?其实道理很简单,首先通过min(x1,x2)次互换操作,再把剩下的r变成b或b变成r,需要|x1−x2|次操作,这俩加起来就是max(x1,x2).)
最后取两种目标串操作的最小值就可以了。

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <deque>
#include <set>
using namespace std;
typedef long long ll;
#define MAX 0x3f3f3f
map<ll,ll> M;
set<ll> S;
char s[100100];
int main()
{
    ll i,a=0,b=0,n,ans1=0,ans2=0;
    cin>>n>>s;
    for(i=0;i<n;i++)//brbr……
    {
        if(i%2==0)
        {
            if(s[i]=='r')
                a++;
        }
        else
        {
            if(s[i]=='b')
                b++;
        }
    }
    ans1=max(a,b);
    a=0,b=0;
    for(i=0;i<n;i++)//rbrb……
    {
        if(i%2==0)
        {
            if(s[i]=='b')
               a++;
        }
        else
        {
            if(s[i]=='r')
                b++;
        }
    }
    ans2=max(a,b);
    cout<<min(ans1,ans2)<<endl;;
    return 0;
}

CodeForces 716B

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个英文字母且不重复,字串中有‘?’表示占位符可表示字母),如果存在则输出该字串‘?’位置用替换后的字母代替,其他不在子串中的‘?’用字母代替即可。如果该字串不存在满足条件的子串,则输出-1.

还是自己写一下比较好

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <deque>
#include <set>
using namespace std;
typedef long long ll;
#define MAX 0x3f3f3f
map<ll,ll> M;
set<ll> S;
int main()
{
    ll n,i,sum=0,j,k,ans=0;
    string s,ss;
    cin>>s;
    n=s.size();
    if(n<26)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    else
    {
        for(i=0;i<=n-26;i++)
        {
            ss=s.substr(i,26);
            //cout<<ss<<endl;
            M.clear();
            S.clear();
            sum=0;
            for(j=0;j<26;j++)
            {
                if(ss[j]=='?')
                    sum++;
                else
                {
                    M[ss[j]-'A']++;
                    S.insert(ss[j]);
                }
            }
            //cout<<sum<<" "<<S.size()<<endl;
            if(sum+S.size()==26)
            {
                for(j=0;j<i;j++)
                {
                    if(s[j]=='?')
                        cout<<"A";
                    else
                        cout<<s[j];
                }
                for(j=0;j<26;j++)
                {
                    if(ss[j]=='?')
                    {
                        for(k=0;k<26;k++)
                        {
                            if(M[k]==0)
                            {
                                printf("%c",k+'A');
                                M[k]=1;
                                break;
                            }
                        }
                    }
                    else
                        cout<<ss[j];
                }
                for(j=i+26;j<n;j++)
                {
                    if(s[j]=='?')
                        cout<<"A";
                    else
                        cout<<s[j];
                }
                break;
            }
            else
                ans++;
        }
        if(ans==n-26+1)
            cout<<"-1"<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ZCY19990813/article/details/82958096