Minimal string CodeForces – 797C】的更多相关文章

Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的最后.要求使得最后s和t均为空串.求字典序最小的可能得到的u. 分析:这道题的操作相当于“将s中字符按从左到右顺序入栈,在任意次的入栈后可以进行任意次的出栈”.显然,最后得到字符串的长度一定是相等的,因此字典序最小就是要前面的尽可能的小.因此可以用一个数组分别记录还未入栈的'a'到'z'的个数,按照…
题目链接 题目难度: 1700rating 题目类型:string+贪心+STL 题目思路: 由于题目要求的最终结果是字典序最小的那个字符串,那么我们从贪心的从’a’开始查找字符串里是否存在,如果存在,就先把后面的所有的该字符放在答案字符串u中(u可以用queue来表示),而字符串t可以用stack来表示.中间的字符串都加入到stack中,当一个字符全加入后,继续从小到大的查找剩余字符串中还剩的字符,并且与栈顶元素进行比较,如果小于栈顶元素,需要先输出栈顶元素.中间的细节比较多,详细看代码.我用…
Minimal string CodeForces - 797C Petya 收到一个长度不超过 105 的字符串 s.他拿了两个额外的空字符串 t 和 u 并决定玩一个游戏.这个游戏有两种合法操作: 将 s 串的第一个字符移动到字符串 t 的末尾. 将 t 串的最后一个字符移动到字符串 u 的末尾. Petya 希望将 s 和 t 都变为空串并且使得串 u 字典序最小. 你需要写一个代码求出最小的字典序. Input 第一行包含一个非空串 s (1 ≤ |s| ≤ 105),只包含小写字母.…
C. Minimal string 题目链接:http://codeforces.com/problemset/problem/797/C time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya recieved a gift of a string s with length up to 105 characters fo…
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾.(2)把t的尾字符取出并添加到u的末尾. 问你当经过一系列操作后,s和t均为空时,字典序最小的u. 题解: 操作的本质: s为队列,t为栈. 贪心思路: (1)找到s中的最小字符c,不断出队并加入t,直至有一次出队的字符等于c,停止出队. (2)当t的尾字符小于等于s中的最小字符时,优先弹出t的尾…
[题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加到t后面; 2.将t的最后一个字符加到u的后面去 要求最后使得s和t字符串变成空串; 并且得到的u的字符串的字典序最小; [题解] i层循环顺序枚举s字符串的每一个字符; 然后把这第i个字符s[i]加入到t的后面去->用一个栈来模拟; 然后维护栈顶的元素和s中剩下的字符串里面字典序最小的字母;->…
http://codeforces.com/contest/862/problem/D 交互题 fflush(stdout) 调试: 先行给出结果,函数代替输入 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <time.h> #include <string> #include <set> #include…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to…
补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后一位生成一个数列. 例如:4 - 2 - counter 进行+4 +4 +4 +4 +2 +4操作会生成数列 04824.每步要加上x或y是任意的. 给你一个数列(由0~9组成的字符串),问你0~9中全部两个数字生成这个包含这个子串的数列中间至少要插入多少数字.以10 * 10矩阵格式输出. 例如…
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at t…
You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is lexicographically less than tt. Let's consider list of all strings consisting of exactly kk lowercase Latin letters, lexicographically not less than ss …
#include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <string> #include <string.h> #define REP(i,a,n) for(int i=a;i<=n;…
You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings. Your task is to replace minimum number of characters in this string with other characters to obtain…
题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率. 用map记录每个字母出现的位置.对于每个字母,用arr[j][k]记录它的所有出现位置的后j位是字母k的个数.对每个j数arr[j]中arr[j][k]等于1的个数,取最大,说明k取这个时区分该字母的概率最大.统计所有字母的该值除以字符串长度即为结果. //#pragma comment(linker,"/STACK:1024000000,1024000000") #include<ios…
题意: 给出了字符串s的内容,字符串t,u初始默认为空,允许做两种操作: 1.把s字符串第一个字符转移到t字符串最后 2.把t字符串最后一个字符转移到u字符串最后 最后要求s.t字符串都为空,问u字符串字典序最小能是多少. 解题关键: 主要就是贪心,按字典序,每贪心完一个字母,往前回溯一次. 1.hash一下每个字母出现的次数,然后贪心选择字典序最小的即可. 2.预处理每个位置能达到的最小的字母,然后贪心.tmp一定是一个单调不减的数组. 3.小于等于而不是等于的原因是abacd这种情况. 反思…
http://codeforces.com/contest/963/problem/D 题解:https://www.cnblogs.com/Blue233333/p/8881614.html 记M为n个串的总长,L为s的长度 询问串的不同的长度只会有sqrt(M)级别个 (最差的情况是串长为1,2,3,...,x,此时M=(x+1)x/2,因此x是sqrt(M)级别的) s的子串中,长度为特定值k的子串个数是L级别的, 由于各个字符串互不相同,这就相当于n个串中所有长度为k的串,分别计算出它们…
虽然只是B题,还是div2的 但感觉挺有意思,所以写一篇博客记录一下 最初的想法是利用DP去做,f[s]=true表示字符串s对应先手赢,否则对应后手赢,大致想了下发现是指数级别的算法,看了下范围直接pass掉 然后就接着想,发现如果两个相等的字符被消掉之后,相等字符的周边靠过来,如果还能消除的话他们就是相等,一想这不就是括号匹配? 然后问题就转化为了寻找合法括号字段的长度 然后就简单了 竟然是用栈来做!!! #include<cstdio> #include<map> #incl…
妈耶,,,被B题卡到哭,C题一发就过了... 字符串问题.首先用vector记录每个字符出现的位置,然后对字符串t的每个字符,用二分查找函数查找,注意用upper_bound查找,对于字符i,首先用变量pre记录第i-1个字符的位置.然后第i个字符的位置只能比 第i-1个字符位置大,所以用二分查一下,如果查不到,答案+1,然后重新查找一遍.若可以则直接更新一下前驱就行了. #include<bits/stdc++.h> using namespace std; ; vector<int…
C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new strin…
题目链接:http://codeforces.com/contest/828/problem/C C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ivan had string s consisting of small English letters. However, hi…
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string s. Namely, he re…
String Reconstruction Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan knows some information about the s…
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string s. Namely, he re…
哇这是我打的第一场cf,第一题都wa了无数次,然后第二题差几分钟交 ,第二天一交就AC了内心是崩溃的.果然我还是太菜l.... A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In a small restaurant there are a tables for one person…
A. k-Factorization 题目大意:给一个数n,求k个大于1的数,乘积为n.(n<=100,000,k<=20) 思路:分解质因数呗 #include<cstdio> #define MN 100000 ],an; int main() { int n,k,i; scanf("%d%d",&n,&k); ;k>&&n>;++i)&&n%i==;--k,n/=i)a[++an]=i; )*pu…
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid…
A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits/stdc++.h> using namespace std; long long n; int k; vector<int> ans; void dfs(int x,long long now,int st){ if(x==k&&now==n){ for(int i=0;i…
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid…
A. k-Factorization 题意:将n分解成k个大于1的数相乘的形式.如果无法分解输出-1. 思路:先打个素因子表,然后暴力判,注意最后跳出的条件. int len,a[N],b[N]; void init() { memset(a,-1,sizeof(a)); a[0]=a[1]=0; memset(b,0,sizeof(b)); len=0; for(int i=2; i<N; i++) if(a[i]) { b[len++]=i; if(N/i<i) continue; for…
                  time limit per test 6 seconds memory limit per test 256 megabytes input standard input output standard output The famous sculptor Cicasso is a Reberlandian spy! These is breaking news in Berlandian papers today. And now the sculptor…