A - Buying A House

题意:给你n个房间,妹子住在第m个房间,你有k块钱,你想买一个离妹子最近的房间。其中相邻的房间之间距离为10,a[i]=0表示已经被别人买了。

题解:扫一遍更新答案即可。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 105; int mp[maxn];
int n,m,k;
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%d",&mp[i]);
}
int Ans = 1000000;
for(int i=1;i<=n;i++){
if(mp[i]==0)continue;
if(mp[i]<=k){
Ans = min(Ans,abs(m-i)*10);
}
}
cout<<Ans<<endl;
}

B - Find The Bone

题意:有n个杯子,m个杯子下面是洞,然后会交换k次杯子。如果球已经在洞里面了,就不会被交换所影响。

题解:模拟即可。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+7; int mp[maxn];
int now = 1;
int n,m,k;
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=m;i++){
int x;scanf("%d",&x);
mp[x]=1;
}
int flag = 0;
for(int i=1;i<=k;i++){
if(mp[now])flag=1;
int x,y;
scanf("%d%d",&x,&y);
if(flag)continue;
if(now==x)now=y;
else if(now==y)now=x;
}
cout<<now<<endl;
}

C - Bank Hacking

题意:给你一棵树,如果砍掉一个点,会使得周围的点+1,间接相连(中间节点必须活着)的点+2。

现在给你每个点的权值,问你最少需要多少的战斗力,能够砍完这棵树。

题解:如果你砍A,那么与A相连的+1,其他的+2。所以你拿个multiset模拟一下就好了。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+7;
vector<int> E[maxn];
int a[maxn],n;
multiset<int>S;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
S.insert(a[i]);
}
for(int i=1;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
E[x].push_back(y);
E[y].push_back(x);
}
int Ans = 2e9;
for(int i=1;i<=n;i++){
int ans = a[i];
S.erase(S.find(a[i]));
for(int j=0;j<E[i].size();j++){
int v = E[i][j];
ans = max(ans,a[v]+1);
S.erase(S.find(a[v]));
}
if(S.size())ans = max(ans,*S.rbegin()+2);
Ans = min(Ans,ans);
S.insert(a[i]);
for(int j=0;j<E[i].size();j++){
int v = E[i][j];
S.insert(a[v]);
}
}
cout<<Ans<<endl;
}

D - Police Stations

题意:给你一棵树,让你删除最多的边,使得任意一个点,到关键点的距离都小于等于d。

题解:暴力bfs,把关键点都压进去跑最短路,然后把最短路径上的边保留下来就好了……

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+8;
int n,k,d;
vector<pair<int,int> >E[maxn];
int vis[maxn],D[maxn];
int main(){
memset(D,-1,sizeof(D));
scanf("%d%d%d",&n,&k,&d);
queue<int> Q;
for(int i=0;i<k;i++){
int x;
scanf("%d",&x);
D[x]=0;
Q.push(x);
}
for(int i=1;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
E[x].push_back(make_pair(y,i));
E[y].push_back(make_pair(x,i));
}
int ans1 = n-1;
while(!Q.empty()){
int now = Q.front();
Q.pop();
if(D[now]==d)continue;
for(int i=0;i<E[now].size();i++){
pair<int,int> next = E[now][i];
if(D[next.first]!=-1)continue;
D[next.first] = D[now] + 1;
Q.push(next.first);
vis[next.second]=1;
ans1--;
}
}
cout<<ans1<<endl;
for(int i=1;i<n;i++){
if(!vis[i])cout<<i<<" ";
}
cout<<endl;
}

E - Exam Cheating

题意:你在考试,你可以抄左右人的答案,你只能抄p次,每次只能看连续的k道题。现在告诉你左右两个人知道哪些题,请问你最多抄对多少题。

题解:dp[x][re][len][type]表示考虑到x位置,当前剩下re次机会,匹配长度还剩下len,当前抄的人是type。然后用记忆化搜索转移即可。

你要么换个人抄,你要么就一直抄这个人。空间复杂度是1000100050*2,会稍微爆空间,所以用short就好了。

#include<bits/stdc++.h>
using namespace std; int a[3][1001],s[3][1001];
short dp[1001][1001][51][2];
int n,p,k,r,x;
short solve(int x,int re,int len,int type){
if(x>n)return 0;
if(re==0){
return s[type][x+len-1]-s[type][x-1];
}
if(dp[x][re][len][type]!=-1)return dp[x][re][len][type];
short& ans = dp[x][re][len][type];
ans = 0;
int Len = min(k,n-x+1);
if(len == 0){
ans = solve(x+1,re,len,type);
// two choices
ans = max(ans,solve(x,re-1,Len,0));
ans = max(ans,solve(x,re-1,Len,1));
}else{
// continue
ans = max(ans,(short)(solve(x+1,re,len-1,type)+(short)a[type][x]));
// change type
ans = max(ans,(short)(solve(x+len,re-1,Len-len,1-type)+(short)(s[2][x+len-1]-s[2][x-1])));
}
return ans;
}
int main(){
memset(dp,-1,sizeof(dp));
scanf("%d%d%d",&n,&p,&k);
scanf("%d",&r);
for(int i=0;i<r;i++){
scanf("%d",&x);
a[0][x]=1;
}
scanf("%d",&r);
for(int i=0;i<r;i++){
scanf("%d",&x);
a[1][x]=1;
}
for(int i=1;i<=n;i++){
for(int j=0;j<2;j++)
s[j][i]+=a[j][i]+s[j][i-1];
s[2][i]+=s[2][i-1];
if(a[0][i]||a[1][i])
s[2][i]++;
}
cout<<solve(1,p,0,0)<<endl;
}

Codeforces Round #408 (Div. 2) 题解【ABCDE】的更多相关文章

  1. Codeforces Round #643 (Div. 2) 题解 (ABCDE)

    目录 A. Sequence with Digits B. Young Explorers C. Count Triangles D. Game With Array E. Restorer Dist ...

  2. Codeforces Round #646 (Div. 2) 题解 (ABCDE)

    目录 A. Odd Selection B. Subsequence Hate C. Game On Leaves D. Guess The Maximums E. Tree Shuffling ht ...

  3. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  4. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  5. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  6. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  7. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  8. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  9. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

随机推荐

  1. js 、c# 编码解码

    escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@ ...

  2. centos6.5环境下svn服务器和客户端配置实用详解

    一.服务器端配置 安装 # yum install -y subversion yum安装软件,不清除软件包的方法 # vim /etc/yum.conf keepcache=0 建立svn版本库数据 ...

  3. Python-HTML CSS题目

    一.简答1.手写html模板,并解释模板每个标签的作用 <!doctype html> 文件类型html <html>页面根 <head>后勤内容 <meta ...

  4. 让Linux任务在后台可靠运行的几种方法

      我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一些耗时较长的任务, 结果却由于网络的不稳定导致任务中途失败.如何让命令提交后不受本地关闭终端窗口/网络 ...

  5. windows下升级node&npm

    一.升级npm npm install -g npm 二.升级node 1.查询node的安装目录 where node 2.在官网下载最新的安装包,直接覆盖安装即可. https://nodejs. ...

  6. OCM_第十天课程:Section5—》数据仓库

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  7. PHP接口继承及接口多继承原理与实现方法详解

    在PHP的接口中,接口可以继承接口.虽然PHP类只能继承一个父类(单继承),但是接口和类不同,接口可以实现多继承,可以继承一个或者多个接口.当然接口的继承也是使用extends关键字,要多个继承的话只 ...

  8. javafx点击鼠标出现弹窗,demo

    在学习javafx的过程中,不知道怎么出现一个弹窗,如,点击一个按钮出现一个修改信息的列表选项 终于在javafx文档示例中发现了类似的东西,记录一下,备忘package demo9_button; ...

  9. 如何批量的在django中对url进行用户登陆限制

    参考URL: https://blog.csdn.net/hanshengzhao/article/details/79540306?utm_source=blogxgwz0 1,首先定义一个内部有装 ...

  10. python全栈开发day37-html

    web准备总结: 结构标准:相当于人的身体.html就是用来制作网页的. 表现标准: 相当于人的衣服.css就是对网页进行美化的. 行为标准: 相当于人的动作.JS就是让网页动起来,具有生命力的 1. ...