国庆第七场训练赛

E - Vitya in the Countryside CodeForces 719A

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.
题意:给出n天,判断n+1天太阳是上升还是下降。
思路:只要我们找到特定的点即可,首先我们可以观察到如果最后一天是15,那么n+1肯定是DOWN,如果最后一个是0,那么n+1肯定是UP;

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
typedef long long LL;
using namespace std;
int main()
{
    int n;
    int b[100];
    while(cin>>n)
    {
        for(int i=0; i<n; i++)
            cin>>b[i];
        if(n==1)
        {
            if(b[n-1]==15)
            {
                cout<<"DOWN"<<endl;
                break;
            }
            else if(b[n-1]==0)
            {
                cout<<"UP"<<endl;
                break;
            }
            else
            {
                cout<<"-1"<<endl;
                break;
            }
        }
        else
        {
            if(b[n-1]==15)
            {
                cout<<"DOWN"<<endl;
                break;
            }
            else if(b[n-1]==0)
            {
                cout<<"UP"<<endl;
                break;
            }
            else if(b[n-1]>=b[n-2])
            {
                cout<<"UP"<<endl;
                break;
            }
            else  if(b[n-1]<=b[n-2])
            {
                cout<<"DOWN"<<endl;
                break;
            }
        }
    }
    return 0;
}

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.
题意:阿纳托利把所有的蟑螂组成了一行。由于他是一个完美主义者,他希望在一行蟑螂的颜色交替。他有一罐黑漆和一罐红漆。在一个回合中,他可以交换任何两只蟑螂,或者拿任何一只蟑螂换颜色。
帮助Anatoly找出最少的回合数,他需要使在线中的蟑螂的颜色交替。
思路:刚看到这个题的时候,只想到了最后结果是brbrbrbr和rbrbrbrb两种情况,没有找到规律,现在恍然大悟,首先我们可以分别统计出这两个情况的时候,他们错误的排列情况,记录下来他们错误个数,分别是用a,b,c,d记录。
1.替换:abs(cnt1-cnt2)
2.交换:(cnt1+cnt2-abs(cnt1-cnt2))/2
解释一下这两个式子,如果按照brbrbr最终结果匹配,假设cnt1=6,cnt2=4,我们可以观察到替换颜色只需要剩下的两个abs(6-4)替换即可,剩下的4个(cnt1+cnt2-abs(cnt1-cnt2))/2我们就是用来交换次数的。

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
typedef long long LL;
using namespace std;
int main()
{
    int n,a=0,b=0,c=0,d=0,ans1=0,ans2=0;
    char s[100010];
    cin>>n;
    getchar();
    gets(s);
    for(int i=0;i<n;i++)//rbrbrbrb
    {
        if(i%2==1)
        {
            if(s[i]!='r')
                a++;
        }
        else
        {
            if(s[i]!='b')
                b++;
        }
    }
    for(int i=0;i<n;i++)//brbrbrbr
    {
        if(i%2==1)
        {
            if(s[i]!='b')
                c++;
        }
        else
        {
            if(s[i]!='r')
                d++;
        }
    }
    ans1=abs(a-b)+(a+b-abs(a-b))/2;
    ans2=abs(c-d)+(c+d-abs(c-d))/2;
    cout<<min(ans1,ans2)<<endl;
    return 0;
}

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的字串,并且让他们A~Z各出现一次,如果长度26的字串有?,可以用任何字母代替。
思路:按要求模拟,找出每一个字串,并判断。

#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
char s[500010];
char a[30]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int vis[30];
int x[30];
int main()
{
    int i,j,k,len,ans,flag;
    gets(s);
    len=strlen(s);
    if(len<26)///小于26不符合
    {
        printf("-1\n");
        return 0;
    }
    ans=0;
    for(i=0; i<len-25; i++)///之所以是25而不是26是为了给全是?留出可能性
    {///大循环是为了找子串
        memset(x,0,sizeof(x));
        memset(vis,0,sizeof(vis));
        flag=1;
        for(j=i; j<i+26; j++)
        {
            if(s[j]>='A'&&s[j]<='Z')
            {
                x[s[j]-'A']++;
                vis[s[j]-'A']=1;///出现过的字母标记一下
                if(x[s[j]-'A']>=2)///子串中的26个字母只能出现一次
                {
                    flag=0;
                    break;
                }
            }
        }
        if(flag)
        {
            ans=1;
            for(j=i; j<i+26; j++)
            {
                if(s[j]=='?')///将?换成剩下的字母
                {
                    for(k=0; k<26; k++)
                    {
                        if(vis[k]==0)
                        {
                            s[j]=a[k];
                            vis[k]=1;///换好了以后要标记
                            break;
                        }
                    }
                }
            }
            if(ans)
            {
                break;
            }
        }
    }
    if(ans)
    {
        for(i=0; i<len; i++)///若是母串中还有?将换成A
        {
            if(s[i]=='?')
            {
                s[i]='A';
            }
        }
        puts(s);
    }
    else
    {
        puts("-1");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值