[codeforces-315D div2]模拟
题目:给两个字符串a、b,问从a中删去若干字符后最多可以得到多少个b串的重复串(bb...b的形式,b的长度不超过100),其中a串是由一个长度不超过100的字符串s重复k次得到的
思路: 暴力匹配a和b,由于s,b的长度都不超过100,标记每次匹配后a串指针的位置对len(s)的模,那么最多有100种标记,每种标记最多导致a串指针移动100*100位,那么在a串的前1e6个字符,一定可以得到重复的标记,而重复的标记之间就是循环节,跳过中间的若干循环节,处理最后剩余的a串字符(一定小于1e6个),继续暴力匹配下就行了。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/* ******************************************************************************** */#include <iostream> //#include <cstdio> //#include <cmath> //#include <cstdlib> //#include <cstring> //#include <vector> //#include <ctime> //#include <deque> //#include <queue> //#include <algorithm> //#include <map> //using namespace std; // //#define pb push_back //#define mp make_pair //#define X first //#define Y second //#define all(a) (a).begin(), (a).end() //#define foreach(a, i) for (typeof(a.begin()) i = a.begin(); i != a.end(); ++ i) //#define fill(a, x) memset(a, x, sizeof(a)) // //void RI(vector<int>&a,int n){a.resize(n);for(int i=0;i<n;i++)scanf("%d",&a[i]);} //void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R> //void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?1:-1; //while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T> //void print(const T t){cout<<t<<endl;}template<typename F,typename...R> //void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T> //void print(T*p, T*q){int d=p<q?1:-1;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;} // //typedef pair<int, int> pii; //typedef long long ll; //typedef unsigned long long ull; // //template<typename T>bool umax(T&a, const T&b){return b>a?false:(a=b,true);} //template<typename T>bool umin(T&a, const T&b){return b<a?false:(a=b,true);} //template<typename T> //void V2A(T a[],const vector<T>&b){for(int i=0;i<b.size();i++)a[i]=b[i];} //template<typename T> //void A2V(vector<T>&a,const T b[]){for(int i=0;i<a.size();i++)a[i]=b[i];} // ///* -------------------------------------------------------------------------------- */ //const int maxn = 1234567;char s[maxn], a[123], c[123];int lena, lenc, b, d, ta;int buf[123], mark[123];void init() { char *ps = s; for (int i = 0; i < b; i ++) { for (int j = 0; j < lena; j ++) { *ps ++ = a[j]; if (ps - s == ta || ps - s > 1111111) return; } }}int work(int);void solve(int &cc, int pp) { if (pp == ta - 1) return ; int rest = ta - pp - 1, cnt = rest / lena; if (rest % lena) cnt ++; ta = cnt * lena; s[ta] = 0; cc += work(pp % lena + 1);}int work(int start) { memset(mark, 0, sizeof(mark)); memset(buf, 0, sizeof(buf)); int cc = 0, nowc = 0; for (int i = start; s[i]; i ++) { if (s[i] == c[nowc]) nowc ++; if (nowc == lenc) { cc ++; nowc = 0; if (mark[i % lena]) { cc += (ta - i - 1) / (i + 1 - mark[i % lena]) * (cc - buf[i % lena]); int pp = i + (ta - i - 1) / (i + 1 - mark[i % lena]) * (i + 1 - mark[i % lena]); solve(cc, pp); return cc; } else { mark[i % lena] = i + 1; buf[i % lena] = cc; } } } return cc;}int main() {#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);#endif // ONLINE_JUDGE cin >> b >> d; scanf("%s%s", a, c); lena = strlen(a); lenc = strlen(c); ta = lena * b; init(); cout << work(0) / d << endl; return 0; //} // // // ///* ******************************************************************************** */ |
[codeforces-315D div2]模拟的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- Codeforces 583 DIV2 Asphalting Roads 模拟
原题链接:http://codeforces.com/problemset/problem/583/A 题意: 很迷很迷,表示没看懂..但是你看样例就秒懂了 题解: 照着样例模拟就好 代码: #inc ...
- codeforces 251 div2 C. Devu and Partitioning of the Array 模拟
C. Devu and Partitioning of the Array time limit per test 1 second memory limit per test 256 megabyt ...
- codeforces 55 div2 C.Title 模拟
C. Title time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
随机推荐
- JavaScript基础1225
JavaScript函数 1.函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块. tip:JavaScript对大小写敏感.关键词function必须是小写,并且必须以与函数名称相同的大小写 ...
- 架构师修炼之微服务部署 - 深入理解Docker镜像
镜像简介 它是一个创建Docker 容器的只读模板,通过DockerFile可以自定义镜像. 它也是一个特殊的文件系统,除了提供容器运行时所需的程序.库.资源.配置等文件外,还包含了一些为运行时准备的 ...
- C#多线程(12):线程池
目录 线程池 ThreadPool 常用属性和方法 线程池说明和示例 线程池线程数 线程池线程数说明 不支持的线程池异步委托 任务取消功能 计时器 线程池 线程池全称为托管线程池,线程池受 .NET ...
- 集合-ArrayList 源码解析
ArrayList是一种以数组实现的List,与数组相比,它具有动态扩展的能力,因此也可称之为动态数组. 类图 ArrayList实现了List, RandomAccess, Cloneable, j ...
- 可以用 Python 编程语言做哪些神奇好玩的事情?除了生孩子不能,其他全都行!
坦克大战 源自于一个用Python写各种小游戏的github合集,star数1k.除了坦克大战外,还包含滑雪者.皮卡丘GOGO.贪吃蛇.推箱子.拼图等游戏. 图片转铅笔画 帮助你快速生成属于自己的铅笔 ...
- rabbitMQ本地安装(Mac版)
一. 首先测试本机器是否安装wget命令 (可以通过wget www.baidu.com来测试,如果有响应则可直接进入步骤二,如果报错或者提示未安装wget则需要先安装wget) 1http://ft ...
- 配置IIS5.5/6.0 支持 Silverlight
在安装完Silverlight1.1 Alpha后,要使自己的IIS服务器支持Silverlight的浏览还需要配置一下IIS网站的 Http头->MIME映射添加内容如下:扩展名 ...
- 工具 在 Nuget 发布自己的包
MSDN : https://docs.microsoft.com/zh-cn/nuget/quickstart/create-and-publish-a-package-using-visual-s ...
- A Tile Painting(循环节)
Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to ...
- [bzoj2427]P2515 [HAOI2010]软件安装(树上背包)
tarjan+树上背包 题目描述 现在我们的手头有 \(N\) 个软件,对于一个软件 \(i\),它要占用 \(W_i\) 的磁盘空间,它的价值为 \(V_i\).我们希望从中选择一些软件安装到一台磁 ...