A - Buying A House

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

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 105;
  4. int mp[maxn];
  5. int n,m,k;
  6. int main(){
  7. scanf("%d%d%d",&n,&m,&k);
  8. for(int i=1;i<=n;i++){
  9. scanf("%d",&mp[i]);
  10. }
  11. int Ans = 1000000;
  12. for(int i=1;i<=n;i++){
  13. if(mp[i]==0)continue;
  14. if(mp[i]<=k){
  15. Ans = min(Ans,abs(m-i)*10);
  16. }
  17. }
  18. cout<<Ans<<endl;
  19. }

B - Find The Bone

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

题解:模拟即可。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e6+7;
  4. int mp[maxn];
  5. int now = 1;
  6. int n,m,k;
  7. int main(){
  8. scanf("%d%d%d",&n,&m,&k);
  9. for(int i=1;i<=m;i++){
  10. int x;scanf("%d",&x);
  11. mp[x]=1;
  12. }
  13. int flag = 0;
  14. for(int i=1;i<=k;i++){
  15. if(mp[now])flag=1;
  16. int x,y;
  17. scanf("%d%d",&x,&y);
  18. if(flag)continue;
  19. if(now==x)now=y;
  20. else if(now==y)now=x;
  21. }
  22. cout<<now<<endl;
  23. }

C - Bank Hacking

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

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

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 3e5+7;
  4. vector<int> E[maxn];
  5. int a[maxn],n;
  6. multiset<int>S;
  7. int main(){
  8. scanf("%d",&n);
  9. for(int i=1;i<=n;i++){
  10. scanf("%d",&a[i]);
  11. S.insert(a[i]);
  12. }
  13. for(int i=1;i<n;i++){
  14. int x,y;
  15. scanf("%d%d",&x,&y);
  16. E[x].push_back(y);
  17. E[y].push_back(x);
  18. }
  19. int Ans = 2e9;
  20. for(int i=1;i<=n;i++){
  21. int ans = a[i];
  22. S.erase(S.find(a[i]));
  23. for(int j=0;j<E[i].size();j++){
  24. int v = E[i][j];
  25. ans = max(ans,a[v]+1);
  26. S.erase(S.find(a[v]));
  27. }
  28. if(S.size())ans = max(ans,*S.rbegin()+2);
  29. Ans = min(Ans,ans);
  30. S.insert(a[i]);
  31. for(int j=0;j<E[i].size();j++){
  32. int v = E[i][j];
  33. S.insert(a[v]);
  34. }
  35. }
  36. cout<<Ans<<endl;
  37. }

D - Police Stations

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

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 5e5+8;
  4. int n,k,d;
  5. vector<pair<int,int> >E[maxn];
  6. int vis[maxn],D[maxn];
  7. int main(){
  8. memset(D,-1,sizeof(D));
  9. scanf("%d%d%d",&n,&k,&d);
  10. queue<int> Q;
  11. for(int i=0;i<k;i++){
  12. int x;
  13. scanf("%d",&x);
  14. D[x]=0;
  15. Q.push(x);
  16. }
  17. for(int i=1;i<n;i++){
  18. int x,y;
  19. scanf("%d%d",&x,&y);
  20. E[x].push_back(make_pair(y,i));
  21. E[y].push_back(make_pair(x,i));
  22. }
  23. int ans1 = n-1;
  24. while(!Q.empty()){
  25. int now = Q.front();
  26. Q.pop();
  27. if(D[now]==d)continue;
  28. for(int i=0;i<E[now].size();i++){
  29. pair<int,int> next = E[now][i];
  30. if(D[next.first]!=-1)continue;
  31. D[next.first] = D[now] + 1;
  32. Q.push(next.first);
  33. vis[next.second]=1;
  34. ans1--;
  35. }
  36. }
  37. cout<<ans1<<endl;
  38. for(int i=1;i<n;i++){
  39. if(!vis[i])cout<<i<<" ";
  40. }
  41. cout<<endl;
  42. }

E - Exam Cheating

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

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

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int a[3][1001],s[3][1001];
  4. short dp[1001][1001][51][2];
  5. int n,p,k,r,x;
  6. short solve(int x,int re,int len,int type){
  7. if(x>n)return 0;
  8. if(re==0){
  9. return s[type][x+len-1]-s[type][x-1];
  10. }
  11. if(dp[x][re][len][type]!=-1)return dp[x][re][len][type];
  12. short& ans = dp[x][re][len][type];
  13. ans = 0;
  14. int Len = min(k,n-x+1);
  15. if(len == 0){
  16. ans = solve(x+1,re,len,type);
  17. // two choices
  18. ans = max(ans,solve(x,re-1,Len,0));
  19. ans = max(ans,solve(x,re-1,Len,1));
  20. }else{
  21. // continue
  22. ans = max(ans,(short)(solve(x+1,re,len-1,type)+(short)a[type][x]));
  23. // change type
  24. ans = max(ans,(short)(solve(x+len,re-1,Len-len,1-type)+(short)(s[2][x+len-1]-s[2][x-1])));
  25. }
  26. return ans;
  27. }
  28. int main(){
  29. memset(dp,-1,sizeof(dp));
  30. scanf("%d%d%d",&n,&p,&k);
  31. scanf("%d",&r);
  32. for(int i=0;i<r;i++){
  33. scanf("%d",&x);
  34. a[0][x]=1;
  35. }
  36. scanf("%d",&r);
  37. for(int i=0;i<r;i++){
  38. scanf("%d",&x);
  39. a[1][x]=1;
  40. }
  41. for(int i=1;i<=n;i++){
  42. for(int j=0;j<2;j++)
  43. s[j][i]+=a[j][i]+s[j][i-1];
  44. s[2][i]+=s[2][i-1];
  45. if(a[0][i]||a[1][i])
  46. s[2][i]++;
  47. }
  48. cout<<solve(1,p,0,0)<<endl;
  49. }

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. Sql 插入自定义主键

    在遇到数据库设计是自增的主键,且需要插入自定义的主键Id时,这个时候如果直接Insert的话,将会发生错误,错误提示信息: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'XXX' ...

  2. oracle ip 改为 机器名

    1 hosts文件 添加                   ip  机器名   这一行 2 修改listner.ora 和tnsora.ora ip改为机器名 3 重启服务

  3. 日常用的css基础和自己常用的js封装

    css基础:base /* * 初始化 */ *::after, *::before { box-sizing: border-box; } body { font-family: 'Microsof ...

  4. Android 图片平铺效果

    我们大家都看过平铺的效果,那么我们都是怎么样才能实现的那,我们其实主要用到的就是api,我们一开始new一个bitmap,就可以了,但是,大家都没有想过,我们还可以用什么方法来做这个事情那,那么我们就 ...

  5. Javascript中Json对象与Json字符串互相转换方法汇总(4种转换方式)

    1.Json对象转Json字符串 JSON.stringify(obj); 2.Json字符串传Json对象 JSON.parse(str);//第一种 $.parseJSON(str);//第二种, ...

  6. 关卡得分(if 嵌套for)与(for嵌套if)

  7. OracleOCP认证 之 Linux基础

    Linux 基础 一.SHELL 1: Shell 简介 shell 是用户和Linux 操作系统之间的接口.Linux 中有多种shell, 其中缺省使用的是bash. Linux 系统的shell ...

  8. css3图片旋转

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  9. Java获取当前时间的年月日方法

    package com.ob; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util ...

  10. java根据word模板导出word文件

    1.word模板文件处理,如下图所示在word 文档中填值的地方写入占位变量 2.将word文档另存为xml文件.编辑如下图,找到填写的占位,修改为${bcrxm}格式 3.将文件后缀名改为.ftl文 ...