国庆10.7

A - Complete the Word(CodeForces 716B)
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个连续的字母,必须字母表中的每一个字母都出现一次,如果串中有问号 ,这个问号可以替换成任何没有出现过的字母,但是最后输出的字符串应该是整个字符串并且不能有问号必需有字母
代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
using namespace std;
char s[50000+5];
int main()
{
    int a[28];
    int flagg=0;
    scanf("%s",s);
    int n=strlen(s);
    if(n<26)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=0; i<n-25; i++)
    {
        int flag=0,ans=0;
        memset(a,0,sizeof(a));
        for(int j=i; j<=i+25; j++)
        {
            if(s[j]=='?')
                continue;
            a[s[j]-'A']++;
            if(a[s[j]-'A']>=2)
            {
                flag=1;
                break;
            }
        }

        if(flag==0)
        {
            flagg=1;
            for(int j=i; j<=i+25; j++)
                if(s[j]=='?')
                    for(int k=0; k<=25; k++)
                        if(a[k]==0)
                        {
                            s[j]=k+'A';
                            a[k]=1;
                            break;
                        }
        }
    }
    for(int i=0;i<n;i++)
        if(s[i]=='?')
          s[i]='A';
    if(flagg==0)
        cout<<"-1";
    else
        puts(s);


}

C-Anatoly and Cockroaches(CodeForces 719B)
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.
要么交换两个蟑螂,要么拿漆给蟑螂刷成别的颜色,问把这一堆蟑螂变成交替的颜色所需要改变的最小次数自己想的思路太麻烦了
AC思路:分别记录奇数和偶数位置的蓝色和红色蟑螂分别的个数,找出可以交换的个数,再把要染色的加上
代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
using namespace std;
char a[100000+5];
int main()
{
    int n,ans=0;
    int b1=0,r1=0,b2=0,r2=0;
    cin>>n;
    scanf("%s",a);
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        {
            if(a[i]=='b')
                b2++;
            else
                r2++;
        }
        else
        {
            if(a[i]=='b')
                b1++;
            else
                r1++;
        }
    }

    int aa,bb;
    if(min(b1,r2)>=min(b2,r1))
    {
        aa=min(b2,r1);
        ans+=aa;
        b2-=aa;
        r1-=aa;
    }
    else
    {
        bb=min(b1,r2);
        ans+=bb;
        b1-=bb;
        r2-=bb;
    }
    ans+=min(max(b2,r1),max(b1,r2));
    cout<<ans<<endl;

}

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.
简洁的AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
    int n,a[95];
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(a[n-1]==0)
        cout<<"UP";
    else if(a[n-1]==15)
        cout<<"DOWN";
    else if(n==1&&a[0]>=1&&a[0]<=14)
        cout<<"-1";
    else if(a[n-1]>a[n-2])
        cout<<"UP";
    else if(a[n-1]<a[n-2])
        cout<<"DOWN";
    return 0;
}

我的代码:
写的太麻烦了(>_<)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <algorithm>
#define ll long long
using namespace std;
int s[200]= {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,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,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,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,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,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
            };
int ss[100];
int main()
{
    int n,a;
    int flag=0;
    ios::sync_with_stdio(false);
    cin>>n;
    if(n==1)
    {
        cin>>a;
        if(a==0)
            cout<<"UP";
        else if(a>=1&&a<=14)
            cout<<"-1";
        else
            cout<<"DOWN";
        return 0;
    }
    for(int i=0;i<n;i++)
        cin>>ss[i];
    int d=0,k;
    for(int i=0;i<200;i++)
    {
           d=0;
           if(ss[0]==s[i])
           {
                d++;
               for(k=1;k<n;k++)
                   if(ss[k]==s[i+k])
                     d++;

               if(d==n)
               {
                   if(s[i+k]>s[i+k-1])
                    cout<<"UP";
                   else
                   cout<<"DOWN";
                   break;
               }
           }

    }




}
本关任务:请读取地铁站点进出站客流数据表(Data.xlsx),完成以下任务: 1)取出第0列,通过去重的方式获得地铁站点编号列表,记为code. 2)采用数据框中的groupby分组计算函数,统计出每个地铁站点每天的进站人数和出站人数,计算结果采用一个数据框sat_num来表示,其中列标签依次为:站点编号、日期、进站人数和出站人数; 3)计算出每个站点国庆节期间(10.1~10.7)的进站人数和出站人数, 计算结果用一个数据框sat_num2来表示,其中列标签依次为:A1_站点编号、A2_进站人数、A3_出站人数。 #********** Begin **********# #本关任务: #请读取地铁站点进出站客流数据表(Data.xlsx),表结构字段如下: # 站点编号、日期、时刻、进站人数、出站人数 #完成以下任务: #1)取出第0列,通过去重的方式获得地铁站点编号列表,记为code #2)采用数据框中的groupby分组计算函数,统计出每个地铁站点每天的进站人数和出站人数, # 计算结果采用一个数据框sat_num来表示,其中列标签依次为:站点编号、日期、进站人数和出站人数; #3)计算出每个站点国庆节期间(10.1~10.7)的进站人数和出站人数, # 计算结果用一个数据框sat_num2来表示,其中列标签依次为:A1_站点编号、A2_进站人数、A3_出站人数。 def return_values(): import pandas as pd A=pd.read_excel('Data.xlsx') code= #按站点编号,日期进行分组,分别统计计算进站人数和出站人数,记为B1和B2 B1= B2= #sat_num结果整理 sat_num=pd.DataFrame(list(B1.index),columns=['A1_站点编号','A2_日期']) sat_num['A3_进站人数']= sat_num['A4_出站人数']= #根据sat_num,筛选国庆期间的数据,记为D D= #对D按站点编号进行分组,分别统计计算进站人数和出站人数,记为D1和D2 D1= D2= #sat_num2结果整理 sat_num2=pd.DataFrame(D1.index,columns=['A1_站点编号']) sat_num2['A2_进站人数']= sat_num2['A3_出站人数']= return(code,sat_num,sat_num2) #********** End **********# 请补全代码
最新发布
03-21
#********** Begin **********# #本关任务: #请读取地铁站点进出站客流数据表(Data.xlsx),表结构字段如下: # 站点编号、日期、时刻、进站人数、出站人数 #完成以下任务: #1)取出第0列,通过去重的方式获得地铁站点编号列表,记为code #2)采用数据框中的groupby分组计算函数,统计出每个地铁站点每天的进站人数和出站人数, # 计算结果采用一个数据框sat_num来表示,其中列标签依次为:站点编号、日期、进站人数和出站人数; #3)计算出每个站点国庆节期间(10.1~10.7)的进站人数和出站人数, # 计算结果用一个数据框sat_num2来表示,其中列标签依次为:A1_站点编号、A2_进站人数、A3_出站人数。 def return_values(): import pandas as pd A=pd.read_excel('Data.xlsx') code= #按站点编号,日期进行分组,分别统计计算进站人数和出站人数,记为B1和B2 B1= B2= #sat_num结果整理 sat_num=pd.DataFrame(list(B1.index),columns=['A1_站点编号','A2_日期']) sat_num['A3_进站人数']= sat_num['A4_出站人数']= #根据sat_num,筛选国庆期间的数据,记为D D= #对D按站点编号进行分组,分别统计计算进站人数和出站人数,记为D1和D2 D1= D2= #sat_num2结果整理 sat_num2=pd.DataFrame(D1.index,columns=['A1_站点编号']) sat_num2['A2_进站人数']= sat_num2['A3_出站人数']= return(code,sat_num,sat_num2) #********** End **********# 写一下这道题,不改变原本的代码
03-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值