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 ...
随机推荐
- 洛谷P1914 小书童——密码
题目背景 某蒟蒻迷上了"小书童",有一天登陆时忘记密码了(他没绑定邮箱or手机),于是便把问题抛给了神犇你. 题目描述 蒟蒻虽然忘记密码,但他还记得密码是由一串字母组成.且密码是由 ...
- Code VS 1002 搭桥
题目描述 Description 有一矩形区域的城市中建筑了若干建筑物,如果某两个单元格有一个点相联系,则它们属于同一座建筑物.现在想在这些建筑物之间搭建一些桥梁,其中桥梁只能沿着矩形的方格的边沿搭建 ...
- [CodeForces]786B Legacy
线段树优化建图. 建立两棵线段树,其上点的点权分别表示"到达这个区间内所有点的最小花费"和"到达这个区间内任意一个点的最小花费". 对于第一种路直接加边即可 对 ...
- 使用shell脚本定时备份web网站代码
#!/bin/bash ############### common file ################ #备份文件存放目录 WEBBACK_DIR="/data/backup/ba ...
- 基于ALSA的WAV播放和录音程序
http://blog.csdn.net/azloong/article/details/6140824 这段时间在探索ALSA架构,从ALSA Core到ALSA Lib,再到Android Aud ...
- CF55C. Pie or die
/* CF55C. Pie or die http://codeforces.com/problemset/problem/55/C 博弈论 乱搞 获胜条件是存在一个棋子到边界的值小于5 */ #in ...
- HDU1850 Being a Good Boy in Spring Festival
/* HDU1850 Being a Good Boy in Spring Festival http://acm.hdu.edu.cn/showproblem.php?pid=1850 博弈论 尼姆 ...
- mysql点滴_02程序中运行sql语句报字符集问题解决
程序中运行 "SELECT t.EVENT_TYPE_ID FROM RATABLE_EVENT_TYPE t WHERE t.NAME='帐期末费用转移事件'" 报错 错误码 ...
- Cocos2D-x设计模式发掘之中的一个:单例模式
http://www.tuicool.com/articles/NBRn2murl=pVtZACoQFKXC3u3uGwMLnTy4YDWihcVg0ata5gy506pmPpQEc0PO9hm6wG ...
- YunOS曙光初现----看好阿里云OS----阿冬专栏!!
阿里云os - YunOS 阿里云OS(YunOS)是阿里巴巴集团的智能手机操作系统,依托于阿里巴巴集团电子商务领域积累的经验和强大的云计算平台,基于LINUX开发. 魅族4阿里yun OS版已上市. ...