【链接】 我是链接,点我呀:)

【题意】

【题解】

按照两个区间的排列方式
我们可以分成以下几种情况
![](https://img2018.cnblogs.com/blog/1251265/201811/1251265-20181107092457518-1766840129.png)
会发现这两个区间的作用
最多只能把两段连续不同的区间变为相同。
那么写个for处理出连续不相同的一段的个数cnt。
根据上面的排列方式。
算出每个cnt对应的答案即可。
别忘了有些情况可以乘2.

【代码】

#include <bits/stdc++.h>
#define ll long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std; const int N = 1e6; int n;
char s[N+10],t[N+10];
vector<pair<int,int> > v; int main(){
#ifdef ccy
freopen("rush.txt","r",stdin);
#endif
int T;
scanf("%d",&T);
while (T--){
scanf("%d",&n);
scanf("%s",s+1);
scanf("%s",t+1);
v.clear();
int l = 0,r = 0;
rep1(i,1,n){
if (s[i]!=t[i]){
if (l==0) l = i;
r = i;
}else{
if (l!=0){
v.push_back(make_pair(l,r));
l = 0;
}
}
}
if (l!=0) v.push_back(make_pair(l,r));
int cnt = v.size();
ll ans = 0;
if (cnt==0){
ans+=1LL*n*(n+1)/2;
printf("%lld\n",ans);
continue;
}
if (cnt==1){
ans+=1LL*(v[0].first-1+n-v[0].second)*2;
ans+=1LL*(v[0].second-v[0].first)*2;
printf("%lld\n",ans);
continue;
}
if (cnt==2){
ans+=6;
printf("%lld\n",ans);
continue;
}
puts("0");
}
return 0;
}

【ZOJ 4060】Flippy Sequence的更多相关文章

  1. 【LeetCode练习题】Permutation Sequence

    Permutation Sequence The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and ...

  2. 【Havel 定理】Degree Sequence of Graph G

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2454 [别人博客粘贴过来的] 博客地址:https://www.cnblogs.com/debug ...

  3. 【POJ 2478】 Farey Sequence

    [题目链接] 点击打开链接 [算法] 不难看出,ans = phi(2) + phi(3) + .... + phi(n-1) + phi(n) 线性筛筛出欧拉函数,预处理前缀和,即可 [代码] #i ...

  4. 【HDU 1005】 Number Sequence

    [题目链接] 点击打开链接 [算法] 矩阵乘法快速幂,即可 [代码] #include<bits/stdc++.h> using namespace std; int a,b,n; str ...

  5. 【codeforces 466D】Increase Sequence

    [题目链接]:http://codeforces.com/problemset/problem/466/D [题意] 给你n个数字; 让你选择若干个区间; 且这些区间[li,ri]; 左端点不能一样; ...

  6. 【Uva 1626】Brackets sequence

    [Link]: [Description] 括号序列由这样的规则生成: 1.空字符是一个括号序列; 2.在括号序列两端加上一对括号也是括号序列; 如(s),[s]; 3.两个括号序列A和B,连在一起, ...

  7. 【codeforces 602D】Lipshitz Sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【ZOJ4060】 Flippy Sequence(规律)

    题意:给定两个长度为n的01序列A和B,要求分别从两个序列中取两段将段中数字取反,使得A和B完全相同,求方案数 n<=1e6,sum(n)<=1e7 思路:现场8Y…… 将A和B异或之后问 ...

  9. 【SPOJ 2319】 BIGSEQ - Sequence (数位DP+高精度)

    BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need ...

随机推荐

  1. HDU1573 X问题【一元线性同余方程组】

    题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1573 题目大意: 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X ...

  2. LeetCode208:Implement Trie (Prefix Tree)

    Implement a trie with insert, search, and startsWith methods. Note: You may assume that all inputs a ...

  3. CSS3:box-sizing:不再为盒子模型而烦恼

    题外话: W3C奉行的标准,就是content-box,就是须要计算边框,填充还有内容的;可是就我个人而言, 比較喜欢的是传统IE6时候的怪异模式,不用考虑容器是否会被撑开(打乱布局); 盒子模型差异 ...

  4. HDU5567/BestCoder Round #63 (div.2) A sequence1 水

    sequence1  Given an array a with length n, could you tell me how many pairs (i,j) ( i < j ) for a ...

  5. [POJ 2536] Gopher ||

    [题目链接] http://poj.org/problem?id=2536 [算法] 匈牙利算法解二分图最大匹配 [代码] #include <algorithm> #include &l ...

  6. js实用篇之数组、字符串常用方法

    常常在开发中,会使用到很多js数组和字符串的处理方法,这里列举一些我常用到的一些,方便大家参考使用. 数组方面 push:向数组尾部增加内容,返回的是新数组的长度. var arr = [1,2,3] ...

  7. Integer应该用==还是equals

    问题引出:“Integer应该用==还是equals” 讨论这个问题之前我们先放一段代码 public static void main(String[] args) { Integer a1 = 2 ...

  8. lua 10进制转换成其它进制table表示

    -- params@num integer -- ~) 默认为10 -- NOTE:先不输出符号 function NumberToArray(num, radix) if type(num) ~= ...

  9. ThreadPoolExecutor理解

    ThreadPoolExecutor组成 ThreadPoolExecutor的核心构造函数: public ThreadPoolExecutor(int corePoolSize, int maxi ...

  10. Typeclassopedia

    https://wiki.haskell.org/wikiupload/8/85/TMR-Issue13.pdf By Brent Yorgey, byorgey@gmail.com Original ...