题目链接:http://codeforces.com/contest/797

A题

题意:给出两个数n, k,问能不能将n分解成k个因子相乘的形式,不能输出-1,能则输出其因子;

思路:将n质因分解,若质因子数目对于k则可行,随便将其组合成k个因子即可,反之则不行;

代码:

 #include <bits/stdc++.h>
using namespace std; const int MAXN=1e5;
int a[MAXN]; int main(void){
int n, k, indx=;
cin >> n >> k;
for(int i=; i<=sqrt(n); i++){
while(n%i==){
a[indx++]=i;
n/=i;
}
}
if(n>) a[indx++]=n;
if(indx<k){
cout << - << endl;
}else{
for(int i=; i<k-; i++){
cout << a[i] << " ";
}
int cnt=;
for(int i=k-; i<indx; i++){
cnt*=a[i];
}
cout << cnt << endl;
}
return ;
}

B题

题意:给出一个含有n个元素的数组,求其子序列的和最大且为奇数,输出其和;

思路:先求出所有正数的和,若为奇数直接输出即可,不然则再加一个最大的负数并使其为奇数或减去一个最小的奇数;

代码:

 #include <bits/stdc++.h>
using namespace std; const int MAXN=1e5+;
int a[MAXN]; int main(void){
int n, cnt=MAXN;
cin >> n;
for(int i=; i<n; i++){
cin >> a[i];
int gg=abs(a[i]);
if((gg&)&&gg<cnt){
cnt=gg;
}
}
sort(a, a+n);
int ans=, indx=n-;
while(a[indx]>){
ans+=a[indx];
indx--;
}
if(ans&){
cout << ans << endl;
}else{
cout << ans-cnt << endl;
}
return ;
}

C题

题意:给出一个字符串,从第一关字符开始去s中字符放入t数组中,可以从任意时刻从t末尾取字符放入u中,问u可能的最小字典序排列;

思路:显然这个过程就是栈的操作过程,那么只需要用栈模拟一下这题即可;

先预处理一个数组str, str[i]存储从s末尾字符到第i个字符中的最小字符;

再遍历一遍s字符串,对于当前地 i 个字符,维护顶元素>str[i],最终得到的出栈顺序即为答案;

代码:

 #include <bits/stdc++.h>
using namespace std; const int MAXN=1e5+;
stack<int> st;
int str[MAXN]; int main(void){
string s;
cin >> s;
int len=s.size();
str[len]=;
for(int i=len-; i>=; i--){
str[i]=min(str[i+], s[i]-'a');
}
int indx=;
for(int i=; i<len; i++){
while(!st.empty()){
int cnt=st.top();
if(cnt<=str[i]){
cout << (char)(cnt+'a');
st.pop();
}else break;
}
st.push(s[i]-'a');
}
while(!st.empty()){
int cnt=st.top();
st.pop();
cout << (char)(cnt+'a');
}
cout << endl;
return ;
}

D题:看懂题目再补。。。

E题

题意:有一个含n个元素的数组,接下来有q个查询,每组给出两个数p, k;

对于每组查询输出达到题目要求的最小步数,要求为:p=k+p+a[p],迭代到p>n为止;

思路:要是直接暴力时间复杂度为O(q*n)肯定会tle的,不过稍微加点技巧就好了;

先对500以内的k打下表,对于k>500的数,p每次都加k,所以最多500次就好了,那么时间复杂度只有O(500*q);

代码:

 #include <bits/stdc++.h>
using namespace std; const int MAXN=1e5+;
int a[MAXN], vis[][MAXN]; int main(void){
int n, q, p, k;
scanf("%d", &n);
for(int i=; i<=n; i++){
scanf("%d", &a[i]);
}
for(int i=; i<=; i++){
for(int j=n; j>; j--){
vis[i][j]=i+j+a[j]>n?:vis[i][a[j]+j+i]+;
}
}
scanf("%d", &q);
while(q--){
scanf("%d%d", &p, &k);
if(k<=) printf("%d\n", vis[k][p]);
else{
int ans=;
while(p<=n){
p+=a[p]+k;
ans++;
}
printf("%d\n", ans);
}
}
return ;
}

Educational Codeforces Round 19 A, B, C, E(xjb)的更多相关文章

  1. Educational Codeforces Round 19

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

  2. Educational Codeforces Round 19 题解【ABCDE】

    A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...

  3. 【Educational Codeforces Round 19】

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

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

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

  5. Educational Codeforces Round 19 C

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

  6. Educational Codeforces Round 19 B

    Description You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to f ...

  7. Educational Codeforces Round 19 A

    Description Given a positive integer n, find k integers (not necessary distinct) such that all these ...

  8. Educational Codeforces Round 19 E. Array Queries(暴力)(DP)

    传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #i ...

  9. Educational Codeforces Round 17

    Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...

随机推荐

  1. g++: command not found的解决

    G++没有装或却没有更新   以下方法都可以试试: centos: yum -y update gcc yum -y install gcc+ gcc-c++   ubuntu: apt-get up ...

  2. asp.net mvc4 之Webapi之应用客户端访问服务器端

    一.说明 客户端项目类型设计为:winform(winform窗体项目类型) 服务器端项目类型设计为:asp.net mvc4  webapi 在这里分为项目运行和调试两种情况讨论: 运行: 这种情况 ...

  3. 九度OJ 1091:棋盘游戏 (DP、BFS、DFS、剪枝)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1497 解决:406 题目描述: 有一个6*6的棋盘,每个棋盘上都有一个数值,现在又一个起始位置和终止位置,请找出一个从起始位置到终止位置代 ...

  4. Redis相关的内核参数解释与设置

    参数 somaxconn /proc/sys/net/core/somaxconn 对于TCP连接,Client和Server连接需要三次握手来建立连接,Server端监听状态会由LISTEN切换为E ...

  5. android系统启动框架、Activity界面显示过程详解

    一.Android系统框架 android的系统架构和其操作系统一样,采用了分层的架构.从架构图看,android分为四个层,从高层到低层分别是应用程序层.应用程序框架层.系统运行库层和linux核心 ...

  6. CSU-1531 Jewelry Exhibition —— 二分图匹配(最小覆盖点)

    题目链接:https://vjudge.net/problem/CSU-1531 Input Output Sample Input 2 1 5 3 0.2 1.5 0.3 4.8 0.4 3.5 4 ...

  7. 如何强制ffmpeg编码时输出一个关键帧

    http://blog.csdn.net/ashlingr/article/details/7829429 如何强制ffmpeg编码时输出一个关键帧   如何强制ffmpeg编码时输出一个关键帧 AV ...

  8. x264 --fullhelp

    >x264 --fullhelp x264 core: Syntax: x264 [options] -o outfile infile Infile can be raw (in which ...

  9. ML assignment #1

    ML assignment #1 Problem: implement classification model to train the Iris dataset and make predicti ...

  10. 腾讯Hermes设计概要——数据分析用的是列存储,词典文件前缀压缩,倒排文件递增id、变长压缩、依然是跳表-本质是lucene啊

    转自:http://data.qq.com/article?id=817 三.Hermes设计概要 架构描述 系统核心进程均采用分散化设计,根据业务发展需求,可随意扩缩容机器; 周期性数据直接通过td ...