CodeForces 716B Complete the Word

留坑!

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=50000+2;
 4 char ca[N];
 5 int main()
 6 {
 7     int i,j;
 8
 9     while(scanf("%s",ca)!=EOF)
10     {
11
12         if(strlen(ca)<26)
13         {
14             printf("-1\n");
15             continue;
16         }
17         int cut,l,r,w;int dp[500];
18         for(i=0; i<strlen(ca); i++)
19         {
20             memset(dp,0,sizeof(dp));
21             cut=w=l=r=0;
22             for(j=i; j<i+26; j++)
23                 if(ca[j]==‘?‘)w++;
24                 else if(!dp[ca[j]]&&(int)ca[j]!=0)
25                     ++cut,dp[ca[j]]=1;
26             if(cut+w==26)
27             {
28                 l=i;
29                 r=l+25;
30                 break;
31             }
32         }
33         if(r==0)
34         {
35             printf("-1\n");
36             continue;
37         }
38         else
39         {
40             char s[26],tem[26];
41             int k=0,x,w;
42             for(x=l; x<=l+25; x++)
43                 if(dp[ca[x]])s[k++]=ca[x];
44             k=0;
45             for(x=0; x<=25; x++)
46             {
47                 int flag=1;
48                 for(w=0; w<strlen(s); w++)
49                 {
50                     if((int)s[w]-‘A‘==x)
51                     {
52                         flag=0;
53                         break;
54                     }
55                 }
56                 if(flag)tem[k++]=(char)(x+‘A‘);
57             }
58             k=0;
59             for(x=l; x<=l+25; x++)
60                 if(ca[x]==‘?‘)ca[x]=tem[k++];
61             for(i=0; i<strlen(ca); i++)
62                 if(ca[i]==‘?‘)ca[i]=‘A‘;
63             puts(ca);
64         }
65     }
66     return 0;
67 }
时间: 2024-08-08 09:40:30

CodeForces 716B Complete the Word的相关文章

Complete the Word CodeForces - 716B

ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists asubstring (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

codeforces 372 div2 Complete the Word 716B

大概有三次的CF没有补了,国庆后,慢慢开始 这个题目,异常之暴力,我自己都觉得代码写的不优美....但是实在只是一个暴力,随便写写就好 遍历数组,每一位枚举26个,判断问号数量或者重复数量.... #include <stdio.h> #include <string> #include <iostream> #include <string.h> using namespace std; char s[] = "QWERTYUIOPLKJHGFD

【Codeforces 716B】Complete the Word

题目链接 [题解] 当时竟然用线段树做的这题... 遍历每个位置. 看看每个位置开始的26个除了问号的字母有没有重复的. 没有的话就ok. 然后按顺序放每个字母就好 [代码] #include <iostream> #include <cstdio> using namespace std; string s; int temp[100]; void _nextAlpha(char &key,int i){ while (key<='Z' && tem

Codeforces 1203F2 Complete the Projects (hard version)

[cf题面](https://codeforces.com/contest/1203/problem/F2 Time limit 2000 ms Memory limit 262144 kB 解题思路 先留坑,吃完饭来填 源代码 #include<cstdio> #include<algorithm> int n,r; struct Data{ int need,delta; bool operator < (const Data & a)const{ if(delt

Codeforces 1203F2 Complete the Projects (hard version)(dp)

啊,dp,万恶的dp. 本来不想补的,被某人押着说div3这么可以不ak于是不得不补了.真是痛苦的经历.(笑) 题目链接:https://codeforces.com/problemset/problem/1203/F2 题目大意:给定任务个数n和初始值r,完成每个任务需要有ai的r值,完成后r值会改变bi,问最多能完成多少任务(要保证最后r>=0) 思路:首先如果是正值的话自然按照a从小到大排一遍能加的都加上,然后问题在于负值.贪心显然不行,或者说这其实就是个背包问题的轻度转换,首先要做的预处

Codeforces 716D - Complete The Graph(最短路)

题意:给定n个点,m条边,以及起点s,终点t,问你图中是否存在s->t的最短路为L,其中权值为0的可以任意修改. 思路:对给定的边分为2类,权重不为0的直接扔进去建图,权重为0的边先存起来.接着跑一遍堆优化的dij,如果dis[t]小于L,那么无论怎么修改权重0的边都没有办法凑出最短路L: 如果dis[t]=L,那么直接输出:如果dis[t]>L,则将原来事先存起来的边一条一条的加进去,权值设为1.每加一条边就跑一次dij,一旦找到dis[t]<=L,就可以终止并输出. PS:原来堆优化

Codeforces 715B. Complete The Graph 最短路,Dijkstra,构造

原文链接https://www.cnblogs.com/zhouzhendong/p/CF715B.html 题解 接下来说的“边”都指代“边权未知的边”. 将所有边都设为 L+1,如果dis(S,T) < L ,那么必然无解. 将所有边都设为 1 ,如果 dis(S,T) > L ,那么必然无解. 考虑将任意一条边的权值+1,则 dis(S,T) 会 +0 或者 +1 . 如果将所有边按照某一个顺序不断+1,直到所有边的权值都是L+1了,那么在这个过程中,dis(S,T) 是递增的,而且一定

Codeforces 1203F1 Complete the Projects (easy version)

cf题面 Time limit 2000 ms Memory limit 262144 kB 解题思路 看见这题觉得贪心可做,那就贪吧.(昨天真是贪心的一天,凌晨才被这两道贪心题虐,下午多校又来,感觉我现在比赛时候想贪心就是瞎猜,猜出一个结论就想办法hack,想不出hack就交上去,然后WA,然后自闭,很难摸到门道) 下面这些是我的做题和思考过程-- 显然要先把能加rating和不掉rating的做了,而且要按照要求从低到高的顺序做,因为如果当前rating能满足要求高的,那也能满足要求低的,如

Codeforces 1228D. Complete Tripartite

传送门 不妨设 $1$ 号点在集合 $1$ 里 那么对于其他点,有且只有所有和 $1$ 没有边的点都在集合 $1$ 里 考虑不在集合 $1$ 的任意一个点 $x$ ,不妨设它在集合 $2$ 里 那么所有不在集合 $1$ 的,和 $x$ 没有边的点都在集合 $2$ 里,剩下的点都一定在集合 $3$ 里 所以集合划分完毕,然后就是判断合法性了,特判当然是越多越好啦! #include<iostream> #include<cstdio> #include<algorithm>