CF 610E. Alphabet Permutations】的更多相关文章

题目:http://codeforces.com/problemset/problem/610/E 如果存在c1,c2在原串相邻且在询问串中c1在c2前面的话,把它们在原串出现次数加起来记作sum,那么n-sum就是答案. 维护一棵线段树,线段树的每个节点存一个k^2的矩阵. 然后修改的话就在线段树上区间修改..(标记下传的时候要注意不要越界TAT... 然后询问的话就k^2搞一下需要被减掉的字符对就好了.. #include<cstring> #include<iostream>…
E. Alphabet Permutations time limit per test:  1 second memory limit per test:  512 megabytes input:  standard input output: standard output You are given a string s of length n, consisting of first k lowercase English letters. We define a c-repeat o…
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取模. 因为取模后至少减半, 复杂度$O(nlognlogC)$ 2. CF 431E Chemistry Experiment 大意: n个试管, 第$i$个试管有$a_i$单位水银, m个操作: 1, 修改$a_x$改为$v$. 2, 将$v$单位水倒入试管, 求一种方案使得有水的试管水银与水总量的最大…
CF 715 E. Complete the Permutations 题目大意:给定两个排列\(p,q\)的一部分.定义两个排列\(p,q\)的距离为使用最少的交换次数使得\(p_i=q_i\).对于所有\(0\leq k\leq n-1\)的所有补全方案中距离为\(k\)的方案数. \(\\\) 将排列看成置换的话,两个完整的排列的距离为\(n-m\),其中\(m\)为循环节个数. 现在考虑将所有存在的不完整的循环节找出来.先连边:对于每个\(i\),连\(a_i\to b_i\),然后若\…
E. Intersection of Permutations 链接 题意: 给定两个序列,询问第一个排列的[l1,r1]和第二个排列[l2,r2]中有多少个共同的数,支持在第二个排列中交换两个数. 分析: 首先求出一个数组,c[i],第二个排列的这个数字在第一个排列中出现的位置.那么查询就是询问c数组中的[l2,r2]中的有多少个数字的在[l1,r1]之间.此时可以差分+离线+树状数组在$nlogn$的时间复杂度内完成. 考虑修改操作,考虑cdq分治.在b排列中交换两个数,那么也就是c数组中交…
题链;http://codeforces.com/problemset/problem/251/B B. Playing with Permutations time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya likes permutations a lot. Recently his mom has p…
给出一个长为n的数列的k个排列(1 ≤ n ≤ 1000; 2 ≤ k ≤ 5).求这个k个数列的最长公共子序列的长度 dp[i]=max{dp[j]+1,where j<i 且j,i相应的字符在k个排列中都保持同样的相对位置} #include <iostream> #include <vector> #include <cstring> #include <cstdio> #include <cmath> #include <al…
题目:http://codeforces.com/contest/1093/problem/E 只能想到转化成查询一个区间里值在一个范围里的数的个数…… 没有想到这样适合用主席树套树状数组维护.不过据说卡空间. 参考了这里的题解:https://www.luogu.org/problemnew/solution/CF1093E 写了CDQ分治.一个值在两个序列里的位置看成两维坐标的话,就是查平面区域内点的个数. 按 x (在第一个序列里的位置)排序,分治操作的时间,y (在第二个序列里的位置)用…
挺有收获的一道题ヾ(◍°∇°◍)ノ゙ 恰好为 m ,这个限制仿佛不是很好处理.一般而言,我所了解的恰好为 k 的条件,不是用组合数 / dp状态转移 / 斜率二分就只剩下容斥了.我们可以先处理出 num[i] 表示至少有 i 个完美位置的方案数,之后再容斥得到 ans[m] (恰好为 m 个).如何获得 num 数组?建立dp状态为 f[i][j][p][q], (其中p, q为01状态)表示dp到第 i 个位置,已经出现了 j 个完美的位置,且 i 和 i + 1 是否被用过.转移的时候分情况…
挺水的一道题~ 拿全排列随便乘一下就好了. #include <cstdio> #include <algorithm> #define N 300004 #define ll long long #define mod 998244353 #define setIO(s) freopen(s".in","r",stdin) using namespace std; struct Node { int a,b; }t[N]; ll fac[N…
[CF715E]Complete the Permutations(容斥,第一类斯特林数) 题面 CF 洛谷 给定两个排列\(p,q\),但是其中有些位置未知,用\(0\)表示. 现在让你补全两个排列,定义两个排列\(p,q\)之间的距离为每次选择\(p\)中两个元素交换,使其变成\(q\)的最小次数. 求距离恰好为\([0,n-1]\)的填数方案数. 加强的题目在\(BZOJ\)上有,戳这里. 题解 看到这道题目就觉得无比熟悉.回头翻了翻发现果然是省队集训的时候的题目... 果然都是原题啊..…
[CF285E]Positions in Permutations(动态规划,容斥) 题面 CF 洛谷 题解 首先发现恰好很不好算,所以转成至少,这样子只需要确定完一部分数之后剩下随意补. 然后套一个二项式反演进行容斥就可以得到答案了. 考虑怎么算至少\(m\)个的贡献, 设\(f[i][j][S]\)表示当前填到了位置\(i\),一个有\(j\)个贡献,\(i\)和\(i+1\)的使用情况是\(S\)的方案数,每次枚举一下这个位置是填\(i+1\)还是\(i-1\)还是其他就可以进行转移了.…
CF Edu Round 71 A There Are Two Types Of Burgers 贪心随便模拟一下 #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; #define MAXN 200006 int n , m; int A[MAXN]; int b , p , f , h , c; int main()…
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:packet reader failure 2. 使用lsnrctl status检查监听,一直没有响应,这个是极少见的情况. 3. 检查数据库状态为OPEN,使用nmon检查系统资源.如下一张截图所示,CPU利用率不高,但是CPU Wait%非常高.这意味着I/O不正常.可能出现了IO等待和争用(IO…
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique permutations: [ [1,1,2], [1,2,1], [2,1,1] ] 分析: 全组合的思想,保证start和end之间交换的时候中间没有与end相同的数字 class Solution…
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1]. 这道题是之前那道Permutations 全排列的延伸,由于输入数组有可能出现重复数字,如果按照之前的算法运算,会有…
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 这道题是求全排列问题,给的输入数组没有重复项,这跟之前的那道Combinations 组合项 和类似,解法基本相同,但是不同点在于那道不同的数字顺序只…
C. Bear and String Distance time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Limak is a little polar bear. He likes nice strings - strings of length n, consisting of lowercase English letter…
链接:http://poj.org/problem?id=2369 Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3039   Accepted: 1639 Description We remind that the permutation of some final set is a one-to-one mapping of the set onto itself. Less formal…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Permutations Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have the following permutations [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] 分析: 全排列实现思想是从start开始,分别和后面的数进行交换,递归求解 class Solution {…
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个点距离多边形边缘最远的距离形成的圆面积减去这个点距离多边形边缘最近的距离形成的圆面积.我们可以得出距离最远的点一定是多边形的顶点.而距离最近的点不一定是多边形的顶点,但是在多边形的边上.我们用勾股定理判断点与每条边形成的三角形的两边角.如果有一个边角是钝角,则表示距离最近的点是顶点.如果都是锐角,则…
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环境下编译器不会自动管理CF对象的内存,所以当我们创建了一个CF对象以后就需要我们使用CFRelease将其手动释放,那么CF和OC相互转化的时候该如何管理内存呢?答案就是我们在需要时可以使用__bridge,__bridge_transfer,__bridge_retained,具体介绍和用法如下…
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web 应用中利用集体智慧构建更加有趣的应用或者得到更好的用户体验.集体智慧是指在大量的人群的行为和数据中收集答案,帮助你对整个人群得到统计意义上的结论,这些结论是我们在单个个体上无法得到的,它往往是某种趋势或者人群中共性的部分. Wikipedia 和 Google 是两个典型的利用集体智慧的 Web…
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Piegirl got bored with binary, decimal and other integer based counting systems. Recently she dis…
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Piegirl was asked to implement two table join operation for distributed database system, minim…
题目描述: Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 解题思路: 这道题目由于是求所有的全排列,比较直观的方法就是递归了 class Solution: # @param num, a l…
Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example,[1,1,2] have the following unique permutations: [ [1,1,2], [1,2,1], [2,1,1] ]和一般的Permutation不一样的是,这种permutation需要排序,使相同的元素能够相邻,选取下一个元素的时…
Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 使用递归解决 class Solution { public: vector<bool> visit; vector<int> num;…
1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需要高效的随即存取,而不在乎插入和删除的效率,使用vector . (2)如果需要大量的插入和删除,而不关心随即存取,则应使用list . #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a…