【Educational Codeforces Round 19】
这场edu蛮简单的……
连道数据结构题都没有……
A.随便质因数分解凑一下即可。
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int a[N],cnt,k,x,n;
int main(){
scanf("%d%d",&n,&k);
for(int i=;k>&&n>;i++)
for(;k>&&n%i==;--k,n/=i)a[++cnt]=i;
if(n==){puts("-1");return ;}
for(int i=;i<=cnt;i++)printf("%d ",a[i]);
printf("%d\n",n);
}
B.读入的时候贪心选一下即可。
#include<bits/stdc++.h>
#define inf 1000000007
using namespace std;
int n,q,ans,mmp=inf;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
int x;scanf("%d",&x);
if(x>)ans+=x;
if(x%!=)mmp=min(abs(x),mmp);
}
if(ans%==)ans-=mmp;
printf("%d\n",ans);
}
C.贪心
#include<bits/stdc++.h>
#define N 100010
using namespace std;
char a[N],t[N],ans[N],s[N],minv[N];
int main(){
scanf("%s",s);int len=strlen(s),m=,k=;
minv[len]='z'+;minv[len-]=s[len-];
for(int i=len-;i>=;i--)minv[i]=min(minv[i+],s[i]);
for(int i=;i<len;i++){
t[m++]=s[i];
while(m&&t[m-]<=minv[i+])ans[k++]=t[--m];
}
ans[k]=;
printf("%s\n",ans);
}
D.扫一下树,计算可能的出现次数(值域过大用map比较好)
然后总共的减去sum即为答案。
#include<bits/stdc++.h>
#define N 100010
#define inf 2147483640
using namespace std;
int n,val[N],lc[N],rc[N],fa[N],ans;
map<int,int> mp;
void dfs(int u,int ql,int qr){
if(u==-)return;if(ql>qr)return;
if(ql<=val[u]&&val[u]<=qr)ans+=mp[val[u]];
dfs(lc[u],ql,min(val[u]-,qr));
dfs(rc[u],max(val[u]+,ql),qr);
}
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
int main(){
n=read();
for(int i=;i<=n;i++){
val[i]=read();lc[i]=read();rc[i]=read();
mp[val[i]]++;fa[lc[i]]=fa[rc[i]]=i;
}
for(int i=;i<=n;i++)if(!fa[i])dfs(i,,inf);
printf("%d\n",n-ans);
}
E.正解应该是dp,然而记忆化搜索还是能水过去……
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int n,a[N],f[][N];
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
int dfs(int u,int k){
if(u>n)return ;
if(k>)return dfs(u+a[u]+k,k)+;
if(f[k][u])return f[k][u];
else return f[k][u]=dfs(u+a[u]+k,k)+;
}
int main(){
n=read();for(int i=;i<=n;i++)a[i]=read();
int q=read();
while(q--){
int u=read(),v=read();
printf("%d\n",dfs(u,v));
}
}
F.比较裸的单调队列优化。
#include<bits/stdc++.h>
#define inf 1000000000000000000ll
#define N 5005
using namespace std;
typedef long long ll;
int n,m,sum,a[N],q[N],l,r;
ll dp[N][N],s[N];
struct Node{int x,y;}b[N];
bool operator <(Node a,Node b){return a.x<b.x;}
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
int main(){
n=read();m=read();
for(int i=;i<=n;i++)a[i]=read(),dp[][i]=inf;
sort(a+,a+n+);
for(int i=;i<=m;i++){b[i].x=read();b[i].y=read();sum+=b[i].y;}
if(sum<n){puts("-1");return ;}sort(b+,b+m+);
for(int i=;i<=m;i++){
for(int j=;j<=n;j++)s[j]=s[j-]+abs(a[j]-b[i].x);
l=;r=;
for(int j=;j<=n;j++){
if(l<=r&&q[l]<j-b[i].y)l++;
while(l<=r&&dp[i-][j]-s[j]<=dp[i-][q[r]]-s[q[r]])r--;
q[++r]=j;if(l<=r)dp[i][j]=dp[i-][q[l]]-s[q[l]]+s[j];
else dp[i][j]=inf;
}
}
cout<<dp[m][n]<<endl;
}
总结:这场题目其实没多大意思……但是思维题比较多。
【Educational Codeforces Round 19】的更多相关文章
- 【Educational Codeforces Round 22】
又打了一场EDU,感觉这场比23难多了啊…… 艹还是我太弱了. A. 随便贪心一下. #include<bits/stdc++.h> using namespace std; ,ans=- ...
- 【Educational Codeforces Round 38】D. Buy a Ticket 堆优化Dijkstra
题意 给定一张无向图,对每个点$i\in S$求$\min_{j\in S} {2\times d(i,j)+a_j}$ 考虑多源多汇最短路会超时,换个角度考虑每个$j$,如果$j=i$,那么答案为$ ...
- 【Educational Codeforces Round 37】F. SUM and REPLACE 线段树+线性筛
题意 给定序列$a_n$,每次将$[L,R]$区间内的数$a_i$替换为$d(a_i)$,或者询问区间和 这题和区间开方有相同的操作 对于$a_i \in (1,10^6)$,$10$次$d(a_i) ...
- 【Educational Codeforces Round 48】
A:https://www.cnblogs.com/myx12345/p/9843001.html B:https://www.cnblogs.com/myx12345/p/9843021.html ...
- Educational Codeforces Round 19 题解【ABCDE】
A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
- 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement
[链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...
- 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot
[链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
随机推荐
- 【bzoj4417】[Shoi2013]超级跳马 矩阵乘法
题目描述 现有一个n行m列的棋盘,一只马欲从棋盘的左上角跳到右下角.每一步它向右跳奇数列,且跳到本行或相邻行.跳越期间,马不能离开棋盘.例如,当n = 3, m = 10时,下图是一种可行的跳法. ...
- Django 2.0 学习(09):Django 静态文件(样式和背景图片)
应用的定制化:静态文件 首先,在polls目录中创建一个名叫static的目录.Django会在该目录里面查找静态文件,类似于Django在polls/template目录下查找模板文件. Djang ...
- 事件驱动与异步IO--待更新
论事件驱动与异步IO 通常,我们写服务器处理模型的程序时,有以下几种模型: (1)每收到一个请求,创建一个新的进程,来处理该请求: (2)每收到一个请求,创建一个新的线程,来处理该请求: (3)每收到 ...
- 【SPOJ】Highways(矩阵树定理)
[SPOJ]Highways(矩阵树定理) 题面 Vjudge 洛谷 题解 矩阵树定理模板题 无向图的矩阵树定理: 对于一条边\((u,v)\),给邻接矩阵上\(G[u][v],G[v][u]\)加一 ...
- BZOJ1023:[SHOI2008]仙人掌图——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1023 Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple ...
- [Leetcode] longest valid parentheses 最长的有效括号
Given a string containing just the characters'('and')', find the length of the longest valid (well-f ...
- HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...
- 【算法】【网络流24题】巨坑待填(成功TJ,有时间再填)
------------------------------------------------------------------------------------ 17/24 --------- ...
- bzoj1483: [HNOI2009]梦幻布丁(链表+启发式合并)
题目大意:一个序列,两种操作. ①把其中的一种数修改成另一种数 ②询问有多少段不同的数如1 2 2 1为3段(1 / 2 2 / 1). 昨晚的BC的C题和这题很类似,于是现学现写居然过了十分开心. ...
- 【树形DP】【UVA10859】 Placing Lampposts
传送门 Description 给定一个\(n\)个点\(m\)条边的无向无环图,选择尽量少的节点,使得所有边都至少有一个顶点被选择.在这个基础上,要求有两个顶点被选择的边数尽可能大 Input 多组 ...