【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
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
随机推荐
- Django 2.0 学习(08):Django 自动化测试
编写我们的第一个测试 确定bug 幸运的是,在polls应用中存在一个小小的bug急需修复:无论Question的发布日期是最近(最后)的日期,还是将来很多天的日期,Question.was_publ ...
- SocketServer-实现并发处理3
用socketserver创建一个服务的步骤: 1 创建一个request handler class(请求处理类),合理选择StreamRequestHandler和DatagramRequest ...
- Mac下docker搭建lamp本地开发环境
1.先在Mac上下载docker:官网下载:下载地址(选择mac版本下载,可能速度较慢) DaoCloud下载:下载地址(速度较快,可能版本较低) 2.装完之后打开: 3.检查一下是否下载成功: $ ...
- 【BZOJ4894】天赋(矩阵树定理)
[BZOJ4894]天赋(矩阵树定理) 题面 BZOJ Description 小明有许多潜在的天赋,他希望学习这些天赋来变得更强.正如许多游戏中一样,小明也有n种潜在的天赋,但有 一些天赋必须是要有 ...
- [LOJ 6004] 圆桌聚餐
link 其实网络流就是再考你如何去建边. 先见$S$,$T$为源点与汇点,然后将$S$连向每一个单位,流量为每个单位的人数,然后将每一个单位连向每一个餐桌,流量为$1$,最后在将每一个餐桌与$T$相 ...
- PHP检测json格式数据
首先要记住json_encode返回的是字符串, 而json_decode返回的是对象 判断数据不是JSON格式: 复制代码代码如下: function is_not_json($str){ ...
- 【初级算法】6. 两个数组的交集 II
题目如下: 给定两个数组,写一个方法来计算它们的交集. 例如: 给定 nums1 = [, , , ], nums2 = [, ], 返回 [, ]. 注意: 输出结果中每个元素出现的次数,应与元素在 ...
- 如何在Linux上安装QQ
我一直无法解决Ubuntu QQ问题,而最近我重装ubuntu之后在网络上找到与QQ相关的内容,网上有大神开发出了新版的wineQQ,解决了我们对QQ的需求.经过尝试,完成了QQ安装 如图 安装的是 ...
- Picture POJ - 1177 (线段树-扫描线)
A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wa ...
- stout代码分析之十一:hashmap和multihashmap
hashmap是std::unordered_map的子类,前者对后者的接口做了进一步封装. hashmap的移动构造函数: hashmap(std::map<Key, Value>&am ...