题目链接: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. pygame 安装教程

    步骤: 1.去官网下载PyGame 注意:要下载对应版本的包 官网地址:http://www.pygame.org/download.shtml 其中,如果python为以下版本: python 3. ...

  2. 九度OJ 1102:最小面积子矩阵 (DP、缓存、剪枝)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1666 解决:504 题目描述: 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 输入: ...

  3. Java类加载器(死磕3)

    [正文]Java类加载器(  CLassLoader ) 死磕3:  揭秘 ClassLoader抽象基类 本小节目录 3.1. 类的加载分类:隐式加载和显示加载 3.2. 加载一个类的五步工作 3. ...

  4. CMake命令笔记

    project 为整个工程设置名称.版本和启用语言 project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])projec ...

  5. Microsoft.AspNetCore.Identity 使用 mysql 报错处理

    1.使用mysql 首先要确定mysql connector 支的版本,正面是链接 https://dev.mysql.com/doc/connector-net/en/connector-net-e ...

  6. 7-2 jmu-python-猜数游戏(10 point(s)) 【python】

    7-2 jmu-python-猜数游戏(10 point(s)) 用户从键盘输入两个整数,第一个数是要猜测的数n(<10),第二个数作为随机种子,随机生成一个1~10的整数,如果该数不等于n,则 ...

  7. Codeforces Round #374 (Div. 2) C. Journey —— DP

    题目链接:http://codeforces.com/contest/721/problem/C C. Journey time limit per test 3 seconds memory lim ...

  8. HDU4848 Wow! Such Conquering! —— dfs + 剪枝

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4848 题解: 一开始读错题目.以为每个点只能访问一遍.其实只要每个点都有被访问就可以了. 首先是用弗洛 ...

  9. Windows服务的快速搭建与调试(C#图解)

    Windows服务的快速搭建与调试(C#图解)   目录 一.什么是Windows 服务? 二.创建Windows 服务与安装/卸载批处理. 三.调试Windows 服务. 正文 一.什么是Windo ...

  10. CodeForces526F:Pudding Monsters (分治)

    In this problem you will meet the simplified model of game Pudding Monsters. An important process in ...