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或bsum1 = 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

2018SDIBT_国庆个人第七场相关推荐

  1. 2020牛客暑期多校训练营(第七场)J.Pointer Analysis

    2020牛客暑期多校训练营(第七场)J.Pointer Analysis 题目链接 题目描述 Pointer analysis, which aims to figure out which obje ...

  2. 汉字书写亟待规范——《中国汉字听写大会》第七场复赛观后感

    汉字书写亟待规范--<中国汉字听写大会>第七场复赛观后感 刚观看完央视<中国汉字听写大会>第七场复赛,心中有颇多感慨,不吐不快啊!与前几次收看<中国汉字听写大会>所 ...

  3. 8.10 第七场 Smzzl with Tropical Taste

    8.10 第七场 Smzzl with Tropical Taste Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/26214 ...

  4. 杭电多校第七场 1011 Kejin Player HDU(6656)

    杭电多校第七场 1011 Kejin Player 题意:给你N行,代表从i级有花费a[i]元的r[i]/s[i]的概率达到i+1级,剩下的概率中可能会到达x[i]级.然后询问从L级到R级的花费会是多 ...

  5. 2019杭电多校 第七场 Kejin Player 6656(求期望值)

    2019杭电多校 第七场 Kejin Player 6656(求期望值) 题目 http://acm.hdu.edu.cn/showproblem.php?pid=6656 题意 给你n,q.表示有n ...

  6. 19级算法训练赛第七场

    19级算法训练赛第七场 传送门:https://vjudge.net/contest/362412#problem/J A - 程序设计:合并数字 蒜头君得到了 n 个数,他想对这些数进行下面这样的操 ...

  7. Contest3412 - 2022中石油大中小学生联合训练第七场

    Contest3412 - 2022中石油大中小学生联合训练第七场 问题 A: 手机号码 问题 I: 找朋友 问题 A: 手机号码 题目描述 奶牛Bessie最近买了一台手机,它的手机号码是:1330 ...

  8. 工业元宇宙三人行系列直播活动第七场在北京举办

    工业元宇宙三人行系列直播活动第七场在北京举办 李正海 2022-4-1 2022年4月1日15:00-17:00,工业元宇宙三人行系列直播活动第七场在北京中国智能制造万里行举办.本次活动由北京金山顶尖 ...

  9. 【缘起•看见】公益捐书宝鸡第七场——走进岐山县凤鸣镇杏园逸夫小学

    缘起看见 公益捐书活动走进岐山县凤鸣镇杏园逸夫小学 为进一步培养青少年的责任担当意识,用实际行动参与公益事业:关爱乡村儿童捐赠图书计划 "缘起•看见"主题公益活动,由陕西省青联社会 ...

最新文章

  1. 7 个小仙女花3年时间写了一本1200页的机器学习算法手册(限时开放下载)
  2. 云计算已成创新基础设施,三大暗流左右未来“云市场”
  3. linux调试crontab,linux - crontab 的调试,启动thin服务器
  4. docker挂载文件躺过的坑
  5. ASP.NET中对STA COM组件的不正确调用产生的w3wp远程DoS
  6. 计算区域中有t 个点的 区域有多少个+计算几何 + 叉乘+sort+ 二分 + map poj 2398 Toy Storage...
  7. java中对象排序_java中 对象的排序
  8. Spring Boot 配置随机数技巧
  9. 适应关键业务环境的加湿系统
  10. HDU 1251 统计难题 (Trie)
  11. 如何完成一个深度学习的模型
  12. phoenix 根据条件更新_教您一步步升级Phoenix BIOS
  13. java把在线图片转化流_图片转换图片流方法(二进制流)
  14. ESP32 EC11 制作电脑音量调节旋钮
  15. 我的脚本-一键禁用启用笔记本自带键盘
  16. Ansys多核仿真报错解决办法
  17. FLV方式实现网页FFmpeg推流无插件播放
  18. 掌上飞车-艳云脚本云控系统
  19. 计算机win7不断重启,win7系统电脑一开机就自动重启的解决方法
  20. LOD地形渲染技术概述

热门文章

  1. Python进阶三部曲网络编程
  2. CentOS6.X内核升级
  3. OKHTTP好文推荐
  4. [回顾]事件对象——event
  5. poj1860(spfa判正环)
  6. linux系统文件查找及管理
  7. redhat 登录不慢 传文件很慢
  8. camera驱动电源配置_基于AD7656-1和ADuC7026评估电源时序控制影响
  9. 非广告--推荐Dynatrace:树立数字化性能管理DPM标杆
  10. APM应用性能管理的过去二十年