Codeforces Round #506 (Div. 3) A-C
CF比赛题解(简单题)
简单题是指自己在比赛期间做出来了
A. Many Equal Substrings
题意
- 给个字符串t,构造一个字符串s,使得s中t出现k次;s的长度最短
- 如t="cat",k=3, minlen(s)=9,s=catcatcat
- 1<=len(t),k<=50
题解
- 稍加思考是个前缀等于后缀的问题,用kmp的next数组模板
- 假设t[0..l-1]==t[n-l....n-1]
- 那么应该不断重复t[l...n-1]这样的子串
- 代码如下(应该好好记住kmp模板,自己还有点慌张)
#include<bits/stdc++.h>
int n,k;
char t[52];
int next[52];
char tar[2510];
//前缀和后缀相等
void kmp_next(int m,char x[]){
int i,j;
j=next[0]=-1;
i=0;
while(i<m){
while(-1!=j &&x[i]!=x[j]) j=next[j];
next[++i]=++j;
}
}
void db(){
printf("db:\n");
for(int i=0;i<=n;i++){
printf("%d\t",next[i]);
}
}
int main(){
scanf("%d %d",&n,&k);
scanf("%s",t);
kmp_next(n,t);
int prefix=next[n];//[0..prefix-1] == [n-1-prefix+1,n-1]
//repeat [prefix...n-1]
//printf("db pre:%d\n",prefix);
int q=0;
for(int i=0;i<prefix;i++){
tar[i]=t[i];
q++;
}
for(int j=0;j<k;j++){
for(int m=prefix;m<n;m++){
tar[j*(n-prefix)+m]=t[m];
q++;
}
}
tar[q]='\0';
printf("%s\n",tar);
return 0;
}
B. Creating the Contest
题意
- 从单调增数组a[]选取子序列b[],满足b[i]*2>=b[i+1],最大化子序列长度
- 需要稍加分析,即通过a[j+1]>2*a[j]这样的条件将a[]分成几段,选取最长一段即可
- cf似乎常常中意这些稍加思考问题变得简单的题目呢
代码
#include<bits/stdc++.h>
int a[200010];
int n;
int solve(){
int res=1;
int b=1;
for(int i=2;i<=n;i++){
if(a[i]>2*a[i-1]){
res=std::max(i-b,res);
b=i;
}
}
res=std::max(n+1-b,res);
return res;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
printf("%d",solve());
return 0;
}
C. Maximal Intersection
题意
- 给出[ai,bi]这样的线段n条,求删除一条后使得剩下(n-1)条线段重叠区域最长
- n<=3*1e5
- 思考线段重叠区域min(bi)-max(ai),考虑删除后的影响可以得到这样的方案
- 排序a[],b[],记作sa[],sb[],遍历之前的每一条边,处理这样情况
- a[i]==sa[n]
- b[i]==sb[1]
代码
#include<bits/stdc++.h>
const int maxn=300010;
int x1[maxn],x2[maxn];
int a[maxn],b[maxn];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&x1[i],&x2[i]);
a[i]=x1[i];b[i]=x2[i];
}
std::sort(x1+1,x1+1+n);
std::sort(x2+1,x2+1+n);
int maxv=0;
for(int i=1;i<=n;i++){
int max1=x1[n];
int min2=x2[1];
if(a[i]==max1) max1=x1[n-1];
if(b[i]==min2) min2=x2[2];
//printf("db %d %d %d\n",max1,min2,min2-max1);
maxv=std::max(min2-max1,maxv);
}
printf("%d\n",maxv);
return 0;
}
感想
- 成为了3题选手,也没有fst,虽然是div3,但毕竟涨rating,自己还是太渣
- cf的数据真的很严格,边界一定会照顾到,一定要算时间复杂度
- 继续努力吧
- div3可以在赛后时间Hack,div1/div2只能在比赛时Hack;自己还没尝试hack滋味
Codeforces Round #506 (Div. 3) A-C的更多相关文章
- Codeforces Round #506 (Div. 3) 题解
Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...
- Codeforces Round #506 (Div. 3) D-F
Codeforces Round #506 (Div. 3) (中等难度) 自己的做题速度大概只尝试了D题,不过TLE D. Concatenated Multiples 题意 数组a[],长度n,给 ...
- Codeforces Round #506 (Div. 3) E
Codeforces Round #506 (Div. 3) E dfs+贪心 #include<bits/stdc++.h> using namespace std; typedef l ...
- Codeforces Round #506 (Div. 3)
题解: div3水的没有什么意思 abc就不说了 d题比较显然的就是用hash 但是不能直接搞 所以我们要枚举他后面那个数的位数 然后用map判断就可以了 刚开始没搞清楚数据范围写了快速乘竟然被hac ...
- Codeforces Round #506 (Div. 3) D. Concatenated Multiples
D. Concatenated Multiples You are given an array aa, consisting of nn positive integers. Let's call ...
- Codeforces Round #506 (Div. 3) C. Maximal Intersection
C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #506 (Div. 3) - D. Concatenated Multiples(思维拼接求是否为k的倍数)
题意 给你N个数字和一个K,问一共有几种拼接数字的方式使得到的数字是K的倍数,拼接:“234”和“123”拼接得到“234123” 分析: N <= 2e5,简单的暴力O(N^2)枚举肯定超时 ...
- 【Codeforces Round #506 (Div. 3) 】
A:https://www.cnblogs.com/myx12345/p/9844334.html B:https://www.cnblogs.com/myx12345/p/9844368.html ...
- Codeforces Round #506 (Div. 3)B.Creating the Contest(dp)
B. Creating the Contest time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- java中Map遍历的四种方式
在java中所有的map都实现了Map接口,因此所有的Map(如HashMap, TreeMap, LinkedHashMap, Hashtable等)都可以用以下的方式去遍历. 方法一:在for循环 ...
- jq实现瀑布流
静态html代码: <!DOCTYPE html><html> <head> <meta charset="utf-8"> < ...
- Python 安装 numpy 以及 matplotlib 的过程
系统:ubuntu 16.04 版本:Python3.5 步骤: 安装 pip sudo apt install python3-pip 查看 pip list 是否有 numpy 以及 matplo ...
- LIS,LCS,LICS 学习笔记
1.最长上升子序列(LIS) 子序列: 1.可以不连续 2.相对位置不变 dp[i][j] 表示前i位置,最大值为j的LIS长度 1. dp[i-1][j] 前i-1位置,最大值为j的LIS长度 (没 ...
- 新人--使用layui做的表格,复杂表头,固定列,操作单元格数据计算,点击查询重载表格,可以选择部分或者全部导出
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ORM框架 SQLAlchemy
什么是ORM 使用关系对象映射进行数据库操作. 将对象转换成SQL,然后使用数据API执行SQL并获取执行结果. 分类 -DB first 手动创建数据库和表,自动生成类 -code first 手动 ...
- github插件
可能是迄今为止最好的GitHub代码浏览插件,基本实现浏览器变成代码阅读器,支持目录列表,交叉索引等功能: O网页链接 http://weibo.com/1963193953/Fdj2cFQ ...
- springboot实现拦截器
你首先需要一个搭建好的springboot项目,具体怎么搭建我还没有相应的随笔可以交给你,可以自己上网上看一下,学习一下,之后我要是总结出来的话,这里面我会通知的 首先这个项目的目录结构是这样子的 首 ...
- hdu 1385 floyd记录路径
可以用floyd 直接记录相应路径 太棒了! http://blog.csdn.net/ice_crazy/article/details/7785111 #include"stdio.h& ...
- wcf的Contract中name的使用
name可以自定义,Contract中的name会更改soap消息中的名称,虽然不影响在服务端代码中的使用 可以看到,在后台代码中使用函数的重用进行编写代码是非常方便的