CodeForces 615C
题意:
给定两个字符串s1,s2利用s1去构造s2,s1有无限个,可以翻转,你最少要用几个s1才能构造s2。输出每一次使用的s1的有效区间。
伪思路:
据说是暴力就能过的题目。然而自己就是暴力差,模拟差,DP差。。。。mdzz好像都差,不会怎么暴力。
其他思路都想过一点,然后剩下两个比较可能的;
①:我暴力一发s2,以s2的字符为开始然后暴力过去,让s1去正的反的匹配,所以怎么记录?但是这样细节上处理太多了,比如这个刚好接上,或者不是刚好接上。这样的细节处理。
②:我暴力一发s2,每次取正反,然后一直暴力到终点,每次取正反暴力。如果正反都是没有结果直接可以标记掉,然后put:-1。
但是这样的不好就是中间的情况的太多了,如果每次都有情况的话,那么就是2^很多次左右吧,但是这个len(s2)是有2100,这么暴力无非是作死。如果每次取最优呢?也就是每次我拿长的。。。这样真的可以么。。。直觉就是80%不行。就是觉得如果我这次正的比较长,然后可能会比较短,然后执行比较短的下次会比较长。然后好像举不出例子,所以要试一发。其实打起来也是很吃力啊。
#include <bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<math.h>
//#include<string.h>
//#include<algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double eps=1e-6;
const double pi=acos(-1.0);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const int N=1200;
char s1[N*2];
char s2[N*2];
int dp[N*2][3];
int main()
{
int flag,n,m,k,j,h1,h2;
int num;
int len1,len2;
scanf("%s%s",s1,s2);
len1=strlen(s1);len2=strlen(s2);
flag=k=0;
num=0;
int s,t;
int x;
for(int i=0;i<len2;){
int nextpos=-1;
int p1,p2;
for(int j=0;j<len1;j++){
int k=j;
int next=i;
while(k<len1&&s1[k]==s2[next])
k++,next++;
if(next>nextpos){
nextpos=next;
p1=j+1;
p2=k;
}
}
for(int j=len1-1;j>=0;j--){
int k=j;
int next=i;
while(k>=0&&s1[k]==s2[next]){
next++;
k--;
}
if(next>nextpos){
nextpos=next;
p1=j+1;
p2=k+2;
}
}
if(i==nextpos){
puts("-1");
return 0;
}
i=nextpos;
dp[num][0]=p1;
dp[num][1]=p2;
num++;
}
printf("%d\n",num);
for(int i=0;i<num;i++)
{
printf("%d %d\n",dp[i][0],dp[i][1]);
}
return 0;
}
CodeForces 615C的更多相关文章
- Codeforces 615C Running Track(DP + Trie树)
题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. ...
- 【28.57%】【codeforces 615C】 Running Track
time limit per test1 second memory limit per test512 megabytes inputstandard input outputstandard ou ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- [Javascript] Use a custom sort function on an Array in Javascript
Sorting in Javascript with sort uses lexical sorting by default, which means it will sort in alphabe ...
- ``Accordian'' Patience
``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patience, the rule ...
- centos或者ubuntu设置ssh免密码登陆
1. 输入 # ssh-keygen -t rsa -P "" 然后一路回车 2.输入 # cat ~/.ssh/id_rsa.pub >> ~/.ssh/aut ...
- ribbon负载均衡进行服务消费
相同服务以不同端口形式注册到eureka上,ribbon从eureka上获取冰进行服务消费,会偶现如下现象: I/O error on GET request for "http://COM ...
- homebrew -v 或homebrew -doctor报错请检查 .bash_profile是否有误
homebrew -doctor报错: /usr/local/Library/Homebrew/global.rb:109:in `split': invalid byte sequence in U ...
- GDI泄露+改EXE名
CDC 应该是成对使用 GetDC and ReleaseDC(不用new and delete) 泄露 1.改变生产exe名称:工程->设置->连接->输出文件名:Release/ ...
- CentOS笔记-系统概述
Linux系统的启动过程并不是大家想象中的那么复杂,其过程可以分为5个阶段: 内核的引导. 当计算机打开电源后,首先是BIOS开机自检,按照BIOS中设置的启动设备(通常是硬盘)来启动. 操作系统接管 ...
- Spark SQL is a Spark module for structured data processing.
http://spark.apache.org/docs/latest/sql-programming-guide.html
- 探索C++的底层机制
探索C++的底层机制 在看这篇文章之前,请你先要明白一点:那就是c++为我们所提供的各种存取控制仅仅是在编译阶段给我们的限制,也就是说是编译器确保了你在完成任务之前的正确行为,如果你的行为不正确,那么 ...
- java 相关博客
Intellij Idea 创建Web项目入门(一) SpringMVC 和 MyBatis 学习笔记,搭配示例,主要讲解一些基础的概念.用法和配置 包含框架有:SpringMVC.MyBaits.A ...