题目链接: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. EasyPusher实现将asterisk直播流以RTSP转发实现通话直播与录像

    本文转自博客:http://blog.csdn.net/jinlong0603/article/details/56047145 EasyPusher RTP直播推送介绍 EasyPusher是一个推 ...

  2. inode ls -li 显示索引节点

    ls -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. --a ...

  3. SQL 关联操作

  4. JVM client模式和Server模式

    我们把jdk安装完成后,在命名行输入java -version 不仅可以看到jdk版本相关信息,还会看到类似与 Java HotSpot(TM) 64-Bit Server VM (build 25. ...

  5. linux iptables:安全应用,防火墙

    iptables:安全应用,防火墙 windows和linux都有防火墙,企业的边缘会部署防火墙保证企业内部的局域网是安全的.针对个人电脑会有防火墙保证系统是安全的. 防火墙是唯一通道. 防火墙分类( ...

  6. jstat监控gc情况

    jstat监控gc情况 JavaJVMJ2SE应用服务器SUN  性能测试过程中,我们该如何监控java虚拟机内存的使用情况,用以判断JVM是否存在内存问题呢?如何判断JVM垃圾回收是否正常?一般的t ...

  7. appcompat_v7出现红叉解决方法

    右键属性,java build path 勾选Android5.5.2

  8. vue组件挂载到全局方法

    在最近的项目中,使用了bootstrap-vue来开发,然而在实际的开发过程中却发现这个UI提供的组件并不能打到我们预期的效果,像alert.modal等组件每个页面引入就得重复引入,并不像eleme ...

  9. 如何刷新本地的DNS缓存?

    为了提高网站的访问速度,系统会在成功访问某网站后将该网站的域名.IP地址信息缓存到本地.下次访问该域名时直接通过IP进行访问.一些网站的域名没有变化,但IP地址发生变化,有可能因本地的DNS缓存没有刷 ...

  10. 整合kxmovie

    下载后发现kxmovie 直接运行是不通的,上面我们已经处理了ffmpeg部分的内容.当然了先处理ffmpeg部分.然后再复制kxmovie/kxmovie到项目中导入相应的文件. 编译报错:UIim ...