【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
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
随机推荐
- BZOJ 1004 Cards(Burnside引理+DP)
因为有着色数的限制,故使用Burnside引理. 添加一个元置换(1,2,,,n)形成m+1种置换,对于每个置换求出循环节的个数, 每个循环节的长度. 则ans=sigma(f(i))/(m+1) % ...
- [CF1037H] Security
题目链接 codeforces. 洛谷. Solution 按照套路,可以\(SAM\)上线段树合并求出\(endpos\)集合,然后随便贪心一下就好了. #include<bits/stdc+ ...
- HDU3065:病毒侵袭持续中——题解
http://acm.hdu.edu.cn/showproblem.php?pid=3065 ———————————————————————————— Problem Description 小t非常 ...
- some of the properties associated with the solution could not be read解决方法
基于TFS管理的解决方案打开时提示:“some of the properties associated with the solution could not be read”,并不影响项目加载,O ...
- sass的mixin,extend,placeholder,function
1. mixin 就是定义了一个函数,可以传参,并且设定默认值,css选择器可以通过@include来引用,mixin混入的代码,就是原样复制,不会合并,会造成冗余 例如: @mixin br6($b ...
- zabbix监控ipmi
@1.假设idrac已经启用,并且使用ipmitool能正确读取数据(本文后面详细描述如何配置) @2.第一节只涉及web配置 1.创建主机 configuration-->hosts--> ...
- 题解【bzoj4653 [NOI2016] 区间】
先按照长度排个序,然后依次添加区间.什么是添加?设这个区间是\([l,r]\),添加就是把\(a_l,a_{l+1},a_{l+2},{...},a_{r}\)都加上\(1\),其中\(a_i\)表示 ...
- bzoj 3246 [Ioi2013]Dreaming 贪心
[Ioi2013]Dreaming Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 638 Solved: 241[Submit][Status][Di ...
- jquery多组图片层次切换的焦点图
效果:
- 2017.6.11 NOIP模拟赛
题目链接: http://files.cnblogs.com/files/TheRoadToTheGold/2017-6.11NOIP%E6%A8%A1%E6%8B%9F%E8%B5%9B.zip 期 ...