P3531 [POI2012]LIT-Letters】的更多相关文章

题目描述 Little Johnny has a very long surname. Yet he is not the only such person in his milieu. As it turns out, one of his friends from kindergarten, Mary, has a surname of the same length, though different from Johnny's. Moreover, their surnames cont…
题目描述 Little Johnny has a very long surname. Yet he is not the only such person in his milieu. As it turns out, one of his friends from kindergarten, Mary, has a surname of the same length, though different from Johnny's. Moreover, their surnames cont…
    这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lower case letters of the English alphabet. The hamsters have a vast and comfortable cage. Byteasar intends to place a display under the cage to visuali…
2789: [Poi2012]Letters Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 278  Solved: 185[Submit][Status][Discuss] Description 给出两个长度相同且由大写英文字母组成的字符串A.B,保证A和B中每种字母出现的次数相同. 现在每次可以交换A中相邻两个字符,求最少需要交换多少次可以使得A变成B. Input   第一行一个正整数n (2<=n<=1,000,000),表示字符串的…
直接求逆序对就行了...时间复杂度O(nlogn) ------------------------------------------------------------------------- #include<bits/stdc++.h>   using namespace std;   #define idx(c) ((c) - 'A') #define lowbit(x) ((x) & -(x))   const int charset = 26; const int ma…
[BZOJ2789][Poi2012]Letters Description 给出两个长度相同且由大写英文字母组成的字符串A.B,保证A和B中每种字母出现的次数相同. 现在每次可以交换A中相邻两个字符,求最少需要交换多少次可以使得A变成B. Input 第一行一个正整数n (2<=n<=1,000,000),表示字符串的长度. 第二行和第三行各一个长度为n的字符串,并且只包含大写英文字母. Output 一个非负整数,表示最少的交换次数. Sample Input 3 ABC BCA Samp…
按照顺序依次找到b串每个字母最后的位置,然后求逆序对. #include<cstdio> #define N 1000010 int n,i,j,k,g[26],nxt[N],bit[N];char a[N],b[N];long long ans; int main(){ for(scanf("%d",&n),gets(a),gets(a+1),gets(b+1),i=1;i<=n;g[a[i]]=i++)nxt[i]=g[a[i]-='A']; for(i=…
题目链接 BZOJ 题解 如果我们给\(A\)中所有字母按顺序编号,给\(B\)中所有字母编上相同的号码 对于\(B\)中同一种,显然号码应该升序 然后求逆序对即可 #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<cmath> #include<map> #define R…
处理数组A,A[i]表示字符串a的第i个字符排序后应去的位置,队列可. 对于多次出现的字符,其在a中的顺序和在b中的顺序应该是一一对应的. #include<cstdio> #include<queue> using namespace std; #define N 1000001 typedef long long ll; queue<int>qs[26]; ll ans; int n,A[N]; char a[N],b[N]; int d[N]; void Upda…
题目描述 给出两个长度相同且由大写英文字母组成的字符串A.B,保证A和B中每种字母出现的次数相同. 现在每次可以交换A中相邻两个字符,求最少需要交换多少次可以使得A变成B. 输入 第一行一个正整数n (2<=n<=1,000,000),表示字符串的长度. 第二行和第三行各一个长度为n的字符串,并且只包含大写英文字母. 输出 一个非负整数,表示最少的交换次数. 样例输入 3 ABC BCA 样例输出 2 题解 树状数组求逆序对 一个结论:将序列A通过交换相邻元素变换为序列B,需要的最小次数为A中…