题目链接: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. Red Black Tree 红黑树 AVL trees 2-3 trees 2-3-4 trees B-trees Red-black trees Balanced search tree 平衡搜索树

    小结: 1.红黑树:典型的用途是实现关联数组 2.旋转 当我们在对红黑树进行插入和删除等操作时,对树做了修改,那么可能会违背红黑树的性质.为了保持红黑树的性质,我们可以通过对树进行旋转,即修改树中某些 ...

  2. [数据挖掘课程笔记]SLIQ算法

    1.数据结构 主要的数据结构有:1.Attribute List  2.Class List 对于数据集,每一个属性都有一个对应的Attribute List.如上图所示,每个Attribute Li ...

  3. spring事件广播

    可参考:http://www.cnblogs.com/atyou/archive/2013/01/07/2850106.html 其中的类图更是精彩,现截至如下:

  4. 解决LoadRunner超时错误

    在录制Web协议脚本回放时超时情况经常出现,产生错误的原因也有很多,解决的方法也不同. 错误现象1:Action.c(16): Error -27728: Step download timeout ...

  5. hdu 1391 Number Steps(规律)

    题意:找规律 思路:找规律 #include<iostream> #include<stdio.h> using namespace std; int main(){ int ...

  6. thrift编译java的问题-(安装thrift0.8.0成功-编译mapkeeper.java成功)

    上一次帖子说了thrift编译java出现错误,由于只用到cpp版的,就将此略过.但是老版本的ycsb不是很好用,于是决定以locall的方式编译mapkeeper供最新版ycsb使用.目前根据 ht ...

  7. [转载]支付宝钱包手势密码破解实战(root过的手机可直接绕过手势密码)

    /* *转自http://blog.csdn.net/hu3167343/article/details/36418063 *本文章由 莫灰灰 编写,转载请注明出处. *作者:莫灰灰    邮箱: m ...

  8. 【UVA12779占位】Largest Circle

    几何题,希望有时间回来解决掉.

  9. zlog日志库的简单封装,以及给debug级别添加颜色显示

    现看看效果如何: 方法如下: 定义相关颜色的宏 #define ESC_START "\033[" #define ESC_END "\033[0m" #def ...

  10. 多线程之----定时器TIMER

    结上一篇  多线程的简单介绍  http://www.cnblogs.com/duanxiaojun/p/6595847.html 在上一讲中我主要是对多线程学习这个系列做了一个大致的学习计划,然后对 ...