A. k-Factorization

题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积。

题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能……

#include<bits/stdc++.h>
using namespace std; long long n;
int k;
vector<int> ans;
void dfs(int x,long long now,int st){
if(x==k&&now==n){
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
exit(0);
}
for(int i=st;i<=n;i++){
if(i*now>n)break;
ans.push_back(i);
dfs(x+1,now*i,i);
ans.pop_back();
}
}
int main(){
cin>>n>>k;
dfs(0,1,2);
cout<<"-1"<<endl;
}

B. Odd sum

题意:让你找到一个子序列,要求和为奇数,且和最大。

题解:首先让所有正数都加起来,如果答案此时为奇数,直接输出。否则你要么减去一个正奇数,要么加上一个负奇数。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
long long a[maxn];
int n;
long long sum = 0;
int main(){
scanf("%d",&n);
long long Tmp = 1e18;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]>0)sum+=a[i];
if(abs(a[i])%2==1)Tmp=min(Tmp,abs(a[i]));
}
if(sum%2==1)cout<<sum<<endl;
else cout<<sum-Tmp<<endl;
}

C. Minimal string

题意:你有一个串s,你有两个操作。第一个操作是从s的开头扔一个串到t的结尾。第二个操作是扔t的结尾到u的结尾。

问你怎么操作,才能使得u的字典序最小。

题解:贪心,记录后缀最小值。如果当前t存的已经是后缀最小值的最小了,那就直接输出就好了。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
char s[maxn],t[maxn],u[maxn],mn[maxn];
int main(){
scanf("%s",s);
int len = strlen(s);
mn[len]='z'+1;
int len2 = 0;
for(int i=len-1;i>=0;i--)
mn[i]=min(mn[i+1],s[i]);
int len3 = 0;
for(int i=0;i<len;i++){
t[len2++]=s[i];
while(len2&&t[len2-1]<=mn[i+1])
u[len3++]=t[--len2];
}
printf("%s\n",u);
}

D. Broken BST

题意:给你一个二叉树,让你用题目中的代码(搜索二叉树)去找每一个节点的值,问你哪些值找不到。

题解:就模拟就好了。唯一的坑点就是节点的val会有相同的情况,这种只需要找到val一样的点就好,并不需要找到同样的那个点。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,v[maxn],l[maxn],r[maxn];
int ans,vis[maxn];
set<int> S;
void dfs(int x,int L,int R){
if(L<v[x]&&v[x]<R){
S.insert(v[x]);
}
if(l[x]!=-1)dfs(l[x],L,min(R,v[x]));
if(r[x]!=-1)dfs(r[x],max(L,v[x]),R);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&v[i],&l[i],&r[i]);
if(l[i]!=-1)vis[l[i]]++;
if(r[i]!=-1)vis[r[i]]++;
}
for(int i=1;i<=n;i++){
if(vis[i]==0){
dfs(i,-2e9,2e9);
}
}
for(int i=1;i<=n;i++)
if(S.find(v[i])!=S.end())
ans++;
cout<<n-ans<<endl;
}

E. Array Queries

题意:给你n个数a[i]。然后q个询问,每个询问给你一个p和k,每次p = p + a[p] + k,直到p>n,问你会经过多少步。

题解:根据k分块即可,小于sqrt的dp预处理,否则直接暴力……

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int a[maxn],n;
int b[maxn][350];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=n;i>=1;i--){
for(int j=1;j<350;j++){
if(i+j+a[i]>n)b[i][j]=1;
else b[i][j]=b[i+a[i]+j][j]+1;
}
}
int q;scanf("%d",&q);
for(int i=1;i<=q;i++){
int x,y;scanf("%d%d",&x,&y);
if(y<350)printf("%d\n",b[x][y]);
else{
int ans = 0;
int now = x;
while(now<=n){
ans = ans + 1;
now = now + a[now] + y;
}
printf("%d\n",ans);
}
}
}

Educational Codeforces Round 19 题解【ABCDE】的更多相关文章

  1. Educational Codeforces Round 19 A, B, C, E(xjb)

    题目链接:http://codeforces.com/contest/797 A题 题意:给出两个数n, k,问能不能将n分解成k个因子相乘的形式,不能输出-1,能则输出其因子: 思路:将n质因分解, ...

  2. Educational Codeforces Round 55 题解

    题解 CF1082A [Vasya and Book] 史上最难A题,没有之一 从题意可以看出,翻到目标页只有三种办法 先从\(x\)到\(1\),再从\(1\)到\(y\) 先从\(x\)到\(n\ ...

  3. Codeforces Educational Codeforces Round 54 题解

    题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...

  4. Educational Codeforces Round 19

    A. k-Factorization 题目大意:给一个数n,求k个大于1的数,乘积为n.(n<=100,000,k<=20) 思路:分解质因数呗 #include<cstdio> ...

  5. Codeforces Educational Codeforces Round 57 题解

    传送门 Div 2的比赛,前四题还有那么多人过,应该是SB题,就不讲了. 这场比赛一堆计数题,很舒服.(虽然我没打) E. The Top Scorer 其实这题也不难,不知道为什么这么少人过. 考虑 ...

  6. Educational Codeforces Round 57题解

    A.Find Divisible 沙比题 显然l和2*l可以直接满足条件. 代码 #include<iostream> #include<cctype> #include< ...

  7. 【Educational Codeforces Round 19】

    这场edu蛮简单的…… 连道数据结构题都没有…… A.随便质因数分解凑一下即可. #include<bits/stdc++.h> #define N 100005 using namesp ...

  8. Educational Codeforces Round 19 A+B+C+E!

    A. k-Factorization 题意:将n分解成k个大于1的数相乘的形式.如果无法分解输出-1. 思路:先打个素因子表,然后暴力判,注意最后跳出的条件. int len,a[N],b[N]; v ...

  9. Educational Codeforces Round 19 C

    Description Petya recieved a gift of a string s with length up to 105 characters for his birthday. H ...

随机推荐

  1. db_recovery_file_dest_size

    select name,space_limit,space_used,number_of_files from v$recovery_file_dest; alter system set db_re ...

  2. centos7.2环境nginx+mysql+php-fpm+svn配置walle自动化部署系统详解

    centos7.2环境nginx+mysql+php-fpm+svn配置walle自动化部署系统详解 操作系统:centos 7.2 x86_64 安装walle系统服务端 1.以下安装,均在宿主机( ...

  3. centos系统初始化流程及实现系统裁剪

    Linux系统的初始化流程: POST:ROM+RAM BIOS: Boot Sequence MBR: 446:bootloader 64: 分区表 2: 5A kernel文件:基本磁盘分区 /s ...

  4. TCP template 代码

    服务端 from socket import * server= socket(AF_INET,SOCK_STREAM) server.bind(('127.0.0.1',8080)) server. ...

  5. asp.net core 通过ajax上传图片及wangEditor图片上传

    asp.net core 通过ajax上传图片 .net core前端代码,因为是通过ajax调用,首先要保证ajax能调用后台代码,具体参见上一篇.net core 使用ajax调用后台代码. 前端 ...

  6. Coursera台大机器学习技法课程笔记05-Kernel Logistic Regression

    这一节主要讲的是如何将Kernel trick 用到 logistic regression上. 从另一个角度来看soft-margin SVM,将其与 logistic regression进行对比 ...

  7. github 推送代码

    一.所有更新一起推送 .git init //初始化本地仓库 . git add . //添加全部文件 .git commit -m 'add all the file' //提交修改 .git st ...

  8. 怎样在win7 IIS中部署网站?

    IIS作为微软web服务器的平台,可以轻松的部署网站,让网站轻而易举的搭建成功,那么如何在IIS中部署一个网站呢,下面就跟小编一起学习一下吧. 第一步:发布IIS文件 1:发布你所要在IIS上部署的网 ...

  9. HDU 4763 求最大长度的串A,使得S满足APAQA

    给一个串,让你找一个子串,形如EAEBE,就是一个串在开头结尾中间各出现一次,问这个E最长是多少 Sample Input5xyabcaaaaaaabaaaxoaaaaa Sample Output0 ...

  10. prometheus简介

    一.prometheus简介 1.1 什么是prometheus? Prometheus是一个开源监控系统,它前身是SoundCloud的警告工具包.从2012年开始,许多公司和组织开始使用Prome ...