官方标签 贪心.字符串 题目描述 输入 输出 样例输入 6 4 5 1 1 3 1 1 5 2 4 1 1 1 1 1 2 4 1 3 2 7 7 5 4 5 5 5 3 5 样例输出 ABABA BABBB A AABB ABABBBB ABABA 说明 题目大意 给定一个长度为m的字符串,并且该字符串初始化由B组成. 根据数组a[],对字符串中的个别地方替换为A a = num[i]; b = m + 1 - num[i]; 如果a < b && s[a] != 'A'或者a &…
[BZOJ3489]A simple rmq problem(KD-Tree) 题面 BZOJ 题解 直接做肯定不好做,首先我们知道我们是一个二维平面数点,但是限制区间只能出现一次很不好办,那么我们给每个数记录一下和它相等的上一个位置和下一个位置,那么这两个位置的限定范围就在区间以外,于是变成了一个\(4\)维数点问题,直接\(KD-Tree\)了. #include<iostream> #include<cstdio> #include<algorithm> usin…
[CF827E]Rusty String 题意:给你一个01串,其中部分字符是'?',?可以是0或1,求所有可能的d,满足存在一种可能得到的01串,在向右移动d格后与自己相同. $n\le 5\times 10^5$ 题解:我们先枚举d,那么一个串符合条件当且仅当:$\forall i \in [0,d), a_i=a_{i+d}=a_{i+2d}=...$,我们可以用fft来判断是否相等.具体地,我们令a串代表正串中的V,b串代表反串中的K,求a和b的卷积c,这样只需要判断$c_d,c_{2d…
[CF903G]Yet Another Maxflow Problem 题意:一张图分为两部分,左边有n个点A,右边有m个点B,所有Ai->Ai+1有边,所有Bi->Bi+1有边,某些Ai->Bj有边,每条边都有一定的容量. 先要求你支持两种操作: 1.修改某条Ai->Ai+1的边的容量2.询问从A1到Bm的最大流 n,m<=100000,流量<=10^9 题解:很有思维含量的题. 首先,我们把求最大流变成求最小割.容易发现,我们最多只会割一条Ai->Ai+1的边…
[BZOJ3489]A simple rmq problem 题面 bzoj 题解 这个题不强制在线的话随便做啊... 考虑强制在线时怎么搞 预处理出一个位置上一个出现的相同数的位置\(pre\)与下一个位置\(nxt\) 则对于一个询问\([l,r]\) 一个位置\(i\)当且仅当\(pre_i<l\)且\(nxt_i>r\) 我们可以将一个位置看作一个点坐标为\((pre_i,nxt_i)\) 要求横坐标\(<l\)且纵坐标\(>r\) 这个可以用简单\(kdTree\) 也可…
[BZOJ3489]A simple rmq problem Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直接输出0.我会采取一些措施强制在线. Input 第一行为两个整数N,M.M是询问数,N是序列的长度(N<=100000,M<=200000) 第二行为N个整数,描述这个序列{ai},其中所有1<=ai<=N 再下面M行,每…
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring (2019年1月22日,复习) [6]ZigZag Conversion (2019年1月22日,复习) [8]String to Integer (atoi) (2019年1月22日,复习) [10]Regular Expression Matching (2019年1月22日,复习) [12]In…
[题解]CF986E Prince's Problem(树上差分+数论性质) 题目大意: 给定你一棵树,有点权\(val_i\le 10^7\).现在有\(m\)组询问给定参数\(x,y,w\)问你对于\((x->y)\)的路径经过的点集\(P\),问你这个东西: \[ \prod_{u \in P} {\mathrm{gcd}(w,val_u)} \mod 1000000007 \] 考虑这样一种做法: 把询问差分成 \[ ans(1,x) \times ans(1,y) \times \ma…
[题解]Rusty String [CF827E] 传送门:\(\text{Rusty String}\) \(\text{[CF827E]}\) [题目描述] 多组数据,每组数据给出一个由 \(V,K,?\) 三种字符组成的字符串,其中 \(?\) 可以替换为 \(V,K\) 中的任意一个,求替换后的字符串可以存在的循环周期有哪些. [分析] 乍一看像是带通配符的字符串匹配(不会的强烈建议去康康这个),由于字符集不大,按照套路就应该枚举两个字符 \(a \ne b\in\{V,K\}\),然后…
题目链接: http://codeforces.com/contest/706/problem/C 题目大意: n(2 ≤ n ≤ 100 000)个字符串(长度不超过100000),翻转费用为Ci(<=109),求所有字符串从上到下符合字典序从小到大的最小费用.无解输出-1. 题目思路: [动态规划] 每个字符串有2种状态,翻转或者不翻转,每次只与上一个字符串是否翻转有关,可以用DP. 费用很大,要用long long. 无解的时候我直接break了WA了好久. // //by coolxxx…
[题意]给定n道题,每月末发放工资m,要求从1解到n,每道题需要在当月初付费ai,下月初付费bi,多道题可以安排在同月,求最少月数. [算法]DP [题解]参考自:[bzoj1700]Problem Solving 解题 dp by GXZlegend 因为当月的选择同时关系着当月和下月,贪心是错误的,有如下反例: 50 5 40 10 10 40 10 5 10 3 10 2 因此考虑DP,令f[i][j]表示解决1~i题,最后一月解决j题的最小月数.(只保证满足当月开销,也就是下月开销之后再…
The value of a string s is equal to the number of different letters which appear in this string. Your task is to calculate the total value of all the palindrome substring. Input The input consists of a single ≤∣s∣≤×^ ). The string s only contains low…
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到boundry,使得boundry * n_edge - sum_edge <= k/b, 或者建立s->t,然后不断extend s->t. /* 4729 */ #include <iostream> #include <sstream> #include <…
KD-Tree(乱搞) Orz zyf教给蒟蒻做法 蒟蒻并不会这题正解……(可持久化树套树?...Orz 对于每个点,我们可以求出pre[i],nex[i],那么询问的答案就是:求max (a[i]),其中 i 满足$ ( pre[i]<ql \ and \ nex[i]>qr\ and\ i \in [ql,qr] ) $ 然后我们以(i,pre[i],nex[i])为坐标……将所有点抽象到三维空间中,每次查询就相当于是一次区域求最值! 这题我的感受: 因为前面做了两道区域求和的……然后思路…
in script,i use HttpWebRequest to get service from network.but it comes a mysterious problem. the source code: string url = "http://apis.baidu.com/apistore/vop/baiduvopjson"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); print…
题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be…
题目描述: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to…
problem 443. String Compression Input ["a","a","b","b","c","c","c"] Output ["a","a","b","b","c","c"] Expected ["] a: Giv…
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be spe…
Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr eat / \ / \ g r e at / \ a t To scramble the s…
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = "aabcc",s2 = "dbbca", When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return false. 思路:做过几道动态规划了,终于也有了…
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr eat / \ / \ g r e at / \ a t To scramble the string, we may ch…
http://blog.csdn.net/shootyou/article/details/44852639 Emoji表情字符现在在APP已经广泛支持了.但是MySQL的UTF8编码对Emoji字符的支持却不是那么好.所以我们经常会遇到这样的异常: Incorrect string value: '\xF0\x90\x8D\x83...' for column 原因是Mysql里UTF8编码最多只能支持3个字节,而Emoji表情字符使用的UTF8编码,很多都是4个字节,有些甚至是6个字节. 解…
Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = "aabcc",s2 = "dbbca", When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return false…
这题用线段树轻松解了,重新用树状数组解,关键点是区间更新.公式推导如下:sum[x] = org_sum[x] + delta[1]*x + delta[2]*(x-1) + delta[x]*1           = org_sum[x] + Sigma(delta[1..x]) * (x+1) - Sigma(delta[i]*i)树状数组增加两个结点信息分别存delta[i] 和 delta[i] * i就好了. /* 3468 */ #include <iostream> #incl…
显然需要贪心,重叠越长越好,这样最终的串长尽可能短.需要注意的是,不要考虑中间结果,显然是个状态dp.先做预处理去重,然后求任意一对串的公共长度. /* 3828 */ #include <iostream> #include <sstream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #includ…
树状数组.Easy. /* 4267 */ #include <iostream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <deque> #include <algorithm> #include <cstdio&g…
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <title></title> </head> <body> <script> var string = (function() { return { /* * 功能:去除左右空格 * 来源:JavaScript语言精粹 * ht…
A Simple Problem with Integers Time Limit:5000MS   Memory Limit:131072K Case Time Limit:2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each…
; //格式为sring输出 // Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); // Label2.Text = "asdfadsf"+a.ToString()+"adsfasdf"; // Label1.Text = string.Format("asdfadsf{0:C}adsfasdf",a);//asdfadsf¥1,234.00adsfasdf // L…