这场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】的更多相关文章

  1. 【Educational Codeforces Round 22】

    又打了一场EDU,感觉这场比23难多了啊…… 艹还是我太弱了. A. 随便贪心一下. #include<bits/stdc++.h> using namespace std; ,ans=- ...

  2. 【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$,那么答案为$ ...

  3. 【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) ...

  4. 【Educational Codeforces Round 48】

    A:https://www.cnblogs.com/myx12345/p/9843001.html B:https://www.cnblogs.com/myx12345/p/9843021.html ...

  5. Educational Codeforces Round 19 题解【ABCDE】

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

  6. 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解

    [比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B  Run for your prize[贪心] ...

  7. 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement

    [链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...

  8. 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot

    [链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...

  9. 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...

随机推荐

  1. 【bzoj1609】[Usaco2008 Feb]Eating Together麻烦的聚餐 dp

    题目描述 为了避免餐厅过分拥挤,FJ要求奶牛们分3批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想所有第3批就餐的奶牛排在队尾,队伍的前端由设定为第1批就餐的奶牛占据,中间的位置就归第2批 ...

  2. 【以前的空间】vijos 1720 阿狸的打字机

    https://www.vijos.org/p/1720 作为一个一个蒟蒻,跪了三个星期,终于在蔡大神的帮助下a了.这题网上的题解很多,不过大都把题解写的太简单了(对因为大神的题解只有三个字:傻叉题) ...

  3. HUD.2544 最短路 (Dijkstra)

    HUD.2544 最短路 (Dijkstra) 题意分析 1表示起点,n表示起点(或者颠倒过来也可以) 建立无向图 从n或者1跑dij即可. 代码总览 #include <bits/stdc++ ...

  4. Wireshark中TCP segment of a reassembled PDU的含义

    By francis_hao    Sep 16,2017   在用Wireshark抓包的时候,经常会看到TCP segment of a reassembled PDU,字面意思是要重组的协议数据 ...

  5. Extjs 动态修改gridPanel列头信息以及store数据的方法

    1 /*******************************checkbox按钮 历史报警信息**************************************/ var check ...

  6. Java的四种引用?用到的场景?

    在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有对象处于可触及(reachable)状态,程序才能使用它.从JDK 1.2版本开始,把对象的引用分 ...

  7. bzoj 4069 [Apio2015]巴厘岛的雕塑 dp

    [Apio2015]巴厘岛的雕塑 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 494  Solved: 238[Submit][Status][Dis ...

  8. Centos6.5+Python2.7 +ffmpeg+opencv2自动安装脚本

    今天安装opencv折腾了多个小时,为以后安装少走弯路,脚本安装 完整 脚本如下: #! /bin/bash sudo yum install -y gcc g++ gtk+-devel libjpe ...

  9. 美国选举问题/完全背包/Knapsack

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Knap ...

  10. git revert HEAD

    使用git reset回退公共远程分支的版本后,需要其他所有人手动用远程master分支覆盖本地master分支,显然,这不是优雅的回退方法,下面我们使用另个一个命令来回退版本: git revert ...