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的更多相关文章

  1. Codeforces Round #506 (Div. 3) 题解

    Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...

  2. Codeforces Round #506 (Div. 3) D-F

    Codeforces Round #506 (Div. 3) (中等难度) 自己的做题速度大概只尝试了D题,不过TLE D. Concatenated Multiples 题意 数组a[],长度n,给 ...

  3. Codeforces Round #506 (Div. 3) E

    Codeforces Round #506 (Div. 3) E dfs+贪心 #include<bits/stdc++.h> using namespace std; typedef l ...

  4. Codeforces Round #506 (Div. 3)

    题解: div3水的没有什么意思 abc就不说了 d题比较显然的就是用hash 但是不能直接搞 所以我们要枚举他后面那个数的位数 然后用map判断就可以了 刚开始没搞清楚数据范围写了快速乘竟然被hac ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #506 (Div. 3) - D. Concatenated Multiples(思维拼接求是否为k的倍数)

    题意 给你N个数字和一个K,问一共有几种拼接数字的方式使得到的数字是K的倍数,拼接:“234”和“123”拼接得到“234123” 分析: N <= 2e5,简单的暴力O(N^2)枚举肯定超时 ...

  8. 【Codeforces Round #506 (Div. 3) 】

    A:https://www.cnblogs.com/myx12345/p/9844334.html B:https://www.cnblogs.com/myx12345/p/9844368.html ...

  9. 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 ...

随机推荐

  1. Docker:分布式系统的软件工程革命(上)

    转自:http://cxwangyi.github.io/story/docker_revolution_1.md.html Docker:分布式系统的软件工程革命(上) 作者:王益 最后更新:201 ...

  2. android 异常解决方案汇总

    1)异常:Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法) 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来. 2.将引用的第三方 ...

  3. Java 内部类机制

    内部类(inner class)是定义在另一个类中的类.为什么需要使用内部类呢?其主要原因有以下三点: 1.内部类方法可以访问该类定义所在的作用域中的数据,包括私有的数据. 2.内部类可以对同一个包中 ...

  4. Centos7 下安装 Docker

    一.简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术:Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使用这个镜像:运行中的这个镜 ...

  5. maven tomcat 插件

    在 pom.xml 中添加如下内容 <!-- 配置 tomcat 插件 --> <build> <plugins> <plugin> <group ...

  6. ZOJ 2315 New Year Bonus Grant

    New Year Bonus Grant Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Or ...

  7. 洛谷—— P1262 间谍网络

    https://www.luogu.org/problem/show?pid=1262 题目描述 由于外国间谍的大量渗入,国家安全正处于高度的危机之中.如果A间谍手中掌握着关于B间谍的犯罪证据,则称A ...

  8. wordpress迁移以及遇到的一些问题[mysql备份导入导出][固定链接404]

    总的问题有两个,一是apache的配置,二是mysql的导出和导入.以及迁移后遇到的一些问题解决过程和方法. A机器为老server.B为新server,A机器使用Appserv,B使用wmap,在配 ...

  9. 建议53:用状态模式美化代码,关于python-state工具包的理解

        在<编写高质量代码:改善python程序的91个建议>的建议53:用状态模式美化代码小节中,介绍了状态模式例如以下:就是当一个对象的内在状态改变时,同意改变其行为,但这个对象看起来 ...

  10. 【CareerCup】Trees and Graphs—Q4.3

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/24744177     题目: Given a sorted (increasing ord ...