【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 ...
随机推荐
- 超简洁代码实现CircleImageView
效果图: 页面代码: public class CircleView extends ImageView { private Paint mPaint = new Paint(); public Ci ...
- 【POJ 3076】 Sudoku
[题目链接] http://poj.org/problem?id=3076 [算法] 将数独问题转化为精确覆盖问题,用Dancing Links求解 [代码] #include <algorit ...
- 部署webservice常见问题汇总
问题一 转自http://blog.csdn.net/xingxing513234072/article/details/38615997 处理程序“WebServiceHandlerFactory- ...
- Docker EE/Docker CE简介与版本规划
随着Docker的不断流行与发展,docker公司(或称为组织)也开启了商业化之路,Docker 从 17.03版本之后分为 CE(Community Edition) 和 EE(Enterprise ...
- Oracle 批量插入值
工作中常遇到将Excel文档数据转为SQL语句,然后再将SQL语句插入到数据库已完成数据转移保存到数据库中,下面介绍下如何一次性插入多条SQL语句,先抛个图: 由于真实数据不变给大家看,所以这里是做了 ...
- Spark2.0.2+Zeppelin0.6.2 环境搭建 初探
0.抱怨与其他(此部分与标题没有太多联系): 首先一点想说的是版本问题,为什么标题我会写清楚版本号呢!原因就是版本不对真的很会坑人. 就在写这篇博客的同一天,我还写了另一篇,是 Hadoop2.7.3 ...
- pdf 转成 一张图片
1.maven依赖 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfb ...
- vs2008bin下Debug bll Release文件 obj下的Debug bll Release文件区别
Bin目录用来存放编译的结果,bin是二进制binrary的英文缩写,因为最初C编译的程序文件都是二进制文件,它有Debug和Release两个版本,分别对应的文件夹为bin/Debug和bin/Re ...
- PostgreSQL的HA解决方案-1主从和备份(master/slave and backup)
一.部署说明 1.1 实施环境 本文档实验环境如下: PGSQL主机: 192.168.1.45 PGSQL备机: 192.168.1.50 软件和系统版本 Pgsql 版本: pgsql 9.2.4 ...
- js实现年月日三级联动
当我们注册一个qq的时候,会看到一个三级年月日的联动菜单,下面简单介绍. <!doctype html> <html lang="en"> <head ...