cf1043D. Mysterious Crime(枚举)
题意
给出\(m\)个长度为\(n\)的排列,问有多少连续公共子串
\(m \leqslant 10, n \leqslant 10^5\)
Sol
非常naive的一道题然而交了3遍才过(昨晚真的困得不行。。)
枚举第一个串的位置,直接维护10个指针,分别表示每个串与第一个串匹配到的位置,同时记录出已经匹配了多少位
因为题目中给出的是排列,所以如果某一位不能匹配了,则需要从新的位置开始
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define ull unsigned long long
#define rg register
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 1e5 + 10, INF = 1e9 + 10, mod = 998244353;
const double eps = 1e-9;
inline int read() {
char c = getchar();
int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M;
int a[11][MAXN], pos[11][MAXN], now[MAXN], len[MAXN];
main() {
N = read(); M = read();
for(int i = 1; i <= M; i++)
for(int j = 1; j <= N; j++) {
a[i][j] = read();
pos[i][a[i][j]] = j;
}
LL ans = 0;
for(int i = 1; i <= N; i++) {
len[1] = i;
for(int j = 2; j <= M; j++) {
if(a[j][now[j] + 1] != a[1][i]) now[j] = pos[j][a[1][i]], len[j] = 1;
else now[j]++, len[j]++;
}
LL mn = INF;
for(int j = 1; j <= M; j++) mn = min(mn, (LL)len[j]);
ans += mn;
}
cout << ans;
return 0;
}
/*
*/
cf1043D. Mysterious Crime(枚举)的更多相关文章
- CF1043D Mysterious Crime
思路: 参考了http://codeforces.com/blog/entry/62797,把第一个序列重标号成1,2,3,...,n,在剩下的序列中寻找形如x, x + 1, x + 2, ...的 ...
- CodeForces 1043D Mysterious Crime 区间合并
题目传送门 题目大意: 给出m个1-n的全排列,问这m个全排列中有几个公共子串. 思路: 首先单个的数字先计算到答案中,有n个. 然后考虑多个数字,如果有两个数字相邻,那么在m个串中必定都能找到这两个 ...
- [题解]Codeforces Round #519 - D. Mysterious Crime
[题目] D. Mysterious Crime [描述] 有m个n排列,求一共有多少个公共子段. 数据范围:1<=n<=100000,1<=m<=10 [思路] 对于第一个排 ...
- 【CF1043D】Mysterious Crime(贡献)
题意:给定m个人,每个人有n个数字且每个人的所有数字都是一个n的排列,求有多少种方案去掉某个前缀和后缀后m个人剩余的部分相等 m<=10,n<=1e5 思路:考虑极长的一段连续匹配的串,因 ...
- 【Codeforces Round #519 by Botan Investments D】Mysterious Crime
[链接] 我是链接,点我呀:) [题意] 相当于问你这m个数组的任意长度公共子串的个数 [题解] 枚举第1个数组以i为起点的子串. 假设i..j是以i开头的子串能匹配的最长的长度. (这个j可以给2. ...
- Mysterious Crime CodeForces - 1043D (哈希)
大意: 给定m个n排列, 求有多少个公共子串. 枚举每个位置, hash求出最大匹配长度. #include <iostream> #include <sstream> #in ...
- D. Mysterious Crime
链接 [http://codeforces.com/contest/1043/problem/D] 题意 给你一个m*n的矩阵(m<=10,n<=1e5), 每一行的数字是1到n里不同的数 ...
- cf1043E. Mysterious Crime(二分 前缀和)
题意 题目链接 Sol 考场上做完前四题的时候大概还剩半个小时吧,那时候已经困的不行了. 看了看E发现好像很可做?? 又仔细看了几眼发现这不是sb题么... 先考虑两个人,假设贡献分别为\((x, y ...
- Codeforces Round #519 D - Mysterious Crime
题目 题意: 在m组数,每组有n个数(数的范围1-n)中,找到某些序列 使它是每组数的一个公共子序列,问这样的某些序列的个数? 思路: 不难想出答案ans是≥n的. 创立一个next数组,使每组中第i ...
随机推荐
- python模块与包详解
<1>.模块:任何 *.py 的文件都可以当作模块使用 import 导入 >>>improt test >>>b=test.a() >> ...
- 如何解决 “invalid resource directory name”, resource “crunch”
Ant and the ADT Plugin for Eclipse are packing the .apk file in a different build chain and temp gen ...
- 4.1、支持向量机(SVM)
1.二分类问题 在以前的博客中,我们介绍了用于处理二分类问题的Logistic Regression算法和用于处理多分类问题的Softmax Regression算法,典型的二分类问题,如图: 对于上 ...
- css modules
https://juejin.im/post/5aa727fc518825364001159b http://www.ruanyifeng.com/blog/2016/06/css_modules.h ...
- JAVA数据结构--哈希表的实现(分离链接法)
哈希表(散列)的定义 散列表(Hash table,也叫哈希表),是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度 ...
- 主库binlog被purge的情形
1.演示实验环境 --主库版本: root@(none)>show variables like 'version'; +---------------+-------------------- ...
- 数据库SQL(1)
EG1:db.LpOutputGroups.GroupBy(q => q.CalcGroupDesc).ToList().OrderByDescending(m => m.First(). ...
- 转 OGG 部署阶段常见问题
序号 问题 解决方案1 "2019-04-13 20:23:55 ERROR OGG-00868 Oracle GoldenGate Capture for Oracle, e_db1.pr ...
- 【温故知新】C#基于事件的异步模式(EAP)
在开发winform和调用asp.net的web service引用的时候,会出现许多命名为 MethodNameAsync 的方法. 例如: winform的按钮点击 this.button1.Cl ...
- eclipse中点不出方法的解决办法
window-preferences-java-editor-Content Assist-Advanced 然后选中右上方的所有 右下方选中一个即可.