【ZOJ 4060】Flippy Sequence
【链接】 我是链接,点我呀:)
【题意】
【题解】
按照两个区间的排列方式
我们可以分成以下几种情况

会发现这两个区间的作用
最多只能把两段连续不同的区间变为相同。
那么写个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的更多相关文章
- 【LeetCode练习题】Permutation Sequence
Permutation Sequence The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and ...
- 【Havel 定理】Degree Sequence of Graph G
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2454 [别人博客粘贴过来的] 博客地址:https://www.cnblogs.com/debug ...
- 【POJ 2478】 Farey Sequence
[题目链接] 点击打开链接 [算法] 不难看出,ans = phi(2) + phi(3) + .... + phi(n-1) + phi(n) 线性筛筛出欧拉函数,预处理前缀和,即可 [代码] #i ...
- 【HDU 1005】 Number Sequence
[题目链接] 点击打开链接 [算法] 矩阵乘法快速幂,即可 [代码] #include<bits/stdc++.h> using namespace std; int a,b,n; str ...
- 【codeforces 466D】Increase Sequence
[题目链接]:http://codeforces.com/problemset/problem/466/D [题意] 给你n个数字; 让你选择若干个区间; 且这些区间[li,ri]; 左端点不能一样; ...
- 【Uva 1626】Brackets sequence
[Link]: [Description] 括号序列由这样的规则生成: 1.空字符是一个括号序列; 2.在括号序列两端加上一对括号也是括号序列; 如(s),[s]; 3.两个括号序列A和B,连在一起, ...
- 【codeforces 602D】Lipshitz Sequence
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【ZOJ4060】 Flippy Sequence(规律)
题意:给定两个长度为n的01序列A和B,要求分别从两个序列中取两段将段中数字取反,使得A和B完全相同,求方案数 n<=1e6,sum(n)<=1e7 思路:现场8Y…… 将A和B异或之后问 ...
- 【SPOJ 2319】 BIGSEQ - Sequence (数位DP+高精度)
BIGSEQ - Sequence You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need ...
随机推荐
- hdu1542 线段树+扫描线+离散化
仅仅想说题目给的欲实际不服 还是这类型的水题吧 建议看之前我写的那个 #include<stdio.h> #include<string.h> #include&l ...
- 启动VIP报CRS-1028/CRS-0223致使VIP状态为UNKNOWN故障分析与解决
CRS版本号为10.2.0.4 1.VIP State为UNKNOWN [root@XXdb1 ~]# crs_stat -t Name Type Target ...
- JDK5.0新特性(静态导入、自动装箱/拆箱、增强for循环、可变参数、枚举、泛形)
JDK5中新增了很多新的java特性,利用这些新语法可以帮助开发人员编写出更加高效.清晰,安全的代码. 这些新特性主要有:1.静态导入2.自动装箱/拆箱3.增强for循环4.可变参数5.枚举6.泛型7 ...
- img标签间距问题
关于img标签间距问题:多个img之间有间距,包含img标签的div之间有间距. <!doctype html> 2 <html lang="en"> 3 ...
- 分别使用Hadoop和Spark实现TopN(1)——唯一键
0.简介 TopN算法是一个经典的算法,由于每个map都只是实现了本地的TopN算法,而假设map有M个,在归约的阶段只有M x N个,这个结果是可以接受的并不会造成性能瓶颈. 这个TopN算法在ma ...
- 牛客练习赛19 -E-托米的饮料
题目描述 好了,现在是小托米的故事啦~~~ 可爱的小托米得到了n瓶饮料. 但他不小心把开盖的工具弄丢了,所以他只能利用饮料瓶来开盖. 已知第i个瓶子的品牌为ai,且其能打开bi品牌的瓶子. 问有几瓶饮 ...
- MVVM实现ViewModel获取View输入验证状态
由于Binding只把Convert成功的值送往Source,当目标中的值Convert失败时Source的值依然是旧值,所以ViewModel必须获取View的输入验证状态,以下是本人的实现. 当“ ...
- CABasicAnimation - 上下滑动动画
#import <UIKit/UIKit.h> @interface TJProgressView : UIView @property(nonatomic,assign)CGFloat ...
- js基础---字符串方法
// var str1="xudandan"; // 字符串长度 var str1_length=str1.length;console.log(str1);console.log ...
- 上传文件到linux系统方法
linux,windows filezilla 方法/步骤 下载 Filezilla client工具,此客户端为免费软件,下载完成后安装,安装一路下一步在这里就不过多阐述了,下载地址 htt ...