A

统计一下每个字母的出现次数然后输出即可

  1. #include <bits/stdc++.h>
  2. #define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
  3. #define fep(i,a,b) for(register int i = (a); i >= (b); --i)
  4. #define ls p<<1
  5. #define rs p<<1|1
  6. #define PII pair<int, int>
  7. #define ll long long
  8. #define ull unsigned long long
  9. #define db double
  10. #define endl '\n'
  11. #define debug(a) cout<<#a<<"="<<a<<endl;
  12. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  13. #define INF 0x3f3f3f3f
  14. using namespace std;
  15. const int N = 1e5+10;
  16. int t;
  17. void solve()
  18. {
  19. int n; string str;
  20. cin >> n >> str;
  21. map<char,int>cnt;
  22. rep(i,0,str.size()-1)
  23. {
  24. cnt[str[i]]++;
  25. }
  26. int ans = 0;
  27. for(auto x:cnt)
  28. {
  29. int num=x.first-'A'+1;
  30. if(x.second>=num) ans++;
  31. }
  32. cout << ans << endl;
  33. }
  34. int main()
  35. {
  36. IOS
  37. // freopen("1.in", "r", stdin);
  38. cin >> t;
  39. while(t --)
  40. solve();
  41. return 0;
  42. }

B

前k个数是后n-k个数的顺序,后面的数逆序即可

  1. #include <bits/stdc++.h>
  2. #define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
  3. #define fep(i,a,b) for(register int i = (a); i >= (b); --i)
  4. #define ls p<<1
  5. #define rs p<<1|1
  6. #define PII pair<int, int>
  7. #define ll long long
  8. #define ull unsigned long long
  9. #define db double
  10. #define endl '\n'
  11. #define debug(a) cout<<#a<<"="<<a<<endl;
  12. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  13. #define INF 0x3f3f3f3f
  14. using namespace std;
  15. const int N = 1e5+10;
  16. int t,a[60];
  17. void solve()
  18. {
  19. int n, k, cnt=1; cin >> n >> k;
  20. rep(i,1,n) a[i]=0;
  21. rep(i,n-k,n) a[cnt++] = i;
  22. fep(i,n-k-1,1) a[cnt++] = i;
  23. rep(i,1,n) cout << a[i] << ' ';
  24. cout << endl;
  25. }
  26. int main()
  27. {
  28. IOS
  29. // freopen("1.in", "r", stdin);
  30. cin >> t;
  31. while(t --)
  32. solve();
  33. return 0;
  34. }

C

  1. #include <bits/stdc++.h>
  2. #define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
  3. #define fep(i,a,b) for(register int i = (a); i >= (b); --i)
  4. #define ls p<<1
  5. #define rs p<<1|1
  6. #define PII pair<int, int>
  7. #define ll long long
  8. #define ull unsigned long long
  9. #define db double
  10. #define endl '\n'
  11. #define debug(a) cout<<#a<<"="<<a<<endl;
  12. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  13. #define INF 0x3f3f3f3f
  14. using namespace std;
  15. const int N = 2e5+10;
  16. int t;
  17. int a[N], b[N], s[N];
  18. void solve()
  19. {
  20. int n, k; cin >> n >> k;
  21. rep(i,1,n) s[i]=0;
  22. rep(i,1,n) cin >> a[i], s[i] = s[i-1]+a[i];
  23. rep(i,1,n) cin >> b[i];
  24. int maxx=-INF, ans=-INF;
  25. rep(i,1,min(k,n))
  26. {
  27. maxx=max(maxx, b[i]);
  28. int cur=s[i]; cur+=max(0,k-i)*maxx;
  29. ans=max(cur,ans);
  30. }
  31. cout << ans << endl;
  32. }
  33. int main()
  34. {
  35. IOS
  36. // freopen("1.in", "r", stdin);
  37. cin >> t;
  38. while(t --)
  39. solve();
  40. return 0;
  41. }

D

考虑维护每一个数组前缀和后缀的最大值

然后考虑3种情况即那个数在中间

a、b、c均可以在中间,

a在中间有b a c和c a b两种情况

b在中间有a b c和c b a两种情况

c在中间有a c b和b a c两种情况

这里只说a在中间的情况

我们枚举a的位置\(i\in[2,n-1]\)

那么对于b a c,b在a左边所以就是b应选择的是\([1,i-1]\)中的最大值,也就是lb[i-1]

c在右边应选择的就是rc[i+1]

这种情况的最大值就是\(a[i]+lb[i-1]+rc[i+1]\)

然后对其他几种情况做同样的处理即可

  1. #include <bits/stdc++.h>
  2. #define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
  3. #define fep(i,a,b) for(register int i = (a); i >= (b); --i)
  4. #define ls p<<1
  5. #define rs p<<1|1
  6. #define PII pair<int, int>
  7. #define ll long long
  8. #define ull unsigned long long
  9. #define db double
  10. #define endl '\n'
  11. #define debug(a) cout<<#a<<"="<<a<<endl;
  12. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  13. #define INF 0x3f3f3f3f
  14. using namespace std;
  15. const int N = 2e5+10;
  16. int t, a[N], b[N], c[N];
  17. int la[N], ra[N], lb[N], rb[N], lc[N], rc[N];
  18. void solve()
  19. {
  20. int n; cin >> n;
  21. rep(i,0,n+1) la[i]=0,ra[i]=0,lb[i]=0,rb[i]=0,lc[i]=0,rc[i]=0;
  22. rep(i,1,n) cin >> a[i];
  23. rep(i,1,n) cin >> b[i];
  24. rep(i,1,n) cin >> c[i];
  25. rep(i,1,n) la[i] = max(la[i-1], a[i]);
  26. fep(i,n,1) ra[i] = max(ra[i+1], a[i]);
  27. rep(i,1,n) lb[i] = max(lb[i-1], b[i]);
  28. fep(i,n,1) rb[i] = max(rb[i+1], b[i]);
  29. rep(i,1,n) lc[i] = max(lc[i-1], c[i]);
  30. fep(i,n,1) rc[i] = max(rc[i+1], c[i]);
  31. ll ans=0;
  32. rep(i,2,n-1)
  33. {
  34. ll maxx=0;
  35. maxx = max(maxx, (ll)a[i] + lb[i-1] + rc[i+1]);
  36. maxx = max(maxx, (ll)a[i] + lc[i-1] + rb[i+1]);
  37. maxx = max(maxx, (ll)b[i] + la[i-1] + rc[i+1]);
  38. maxx = max(maxx, (ll)b[i] + lc[i-1] + ra[i+1]);
  39. maxx = max(maxx, (ll)c[i] + la[i-1] + rb[i+1]);
  40. maxx = max(maxx, (ll)c[i] + lb[i-1] + ra[i+1]);
  41. ans = max(ans, maxx);
  42. }
  43. cout << ans << endl;
  44. }
  45. int main()
  46. {
  47. IOS
  48. // freopen("1.in", "r", stdin);
  49. cin >> t;
  50. while(t --)
  51. solve();
  52. return 0;
  53. }

E1、E2

这道题目从数学的角度推公式比较好理解

考虑A、B选择的策略

考虑两列

a:x,y

b:u,v

a选择前面的得到的结果是x-1-(v-1)=x-v

a选择后面的得到的结果是y-1-(u-1)=y-u

哪个更优选择哪个

\((x-v)>(y-u) \rightarrow x+u > y+v也就是每个人会选择当前a[i]+b[i]\)值较大的这一列进行操作

  1. #include <bits/stdc++.h>
  2. #define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
  3. #define fep(i,a,b) for(register int i = (a); i >= (b); --i)
  4. #define ls p<<1
  5. #define rs p<<1|1
  6. #define PII pair<int, int>
  7. #define ll long long
  8. #define ull unsigned long long
  9. #define db double
  10. #define endl '\n'
  11. #define debug(a) cout<<#a<<"="<<a<<endl;
  12. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  13. #define INF 0x3f3f3f3f
  14. using namespace std;
  15. const int N = 2e5+10;
  16. int t;
  17. struct wy
  18. {
  19. ll x, y, sum;
  20. }a[N];
  21. bool cmp(wy a, wy b)
  22. {
  23. return a.sum > b.sum;
  24. }
  25. void solve()
  26. {
  27. int n; cin >> n;
  28. rep(i,1,n) cin >> a[i].x;
  29. rep(i,1,n) cin >> a[i].y, a[i].sum=a[i].x+a[i].y;
  30. sort(a+1,a+1+n, cmp);
  31. ll ans=0;
  32. rep(i,1,n)
  33. {
  34. if(i&1) ans += a[i].x-1;
  35. else ans -= a[i].y-1;
  36. }
  37. cout << ans << endl;
  38. }
  39. int main()
  40. {
  41. IOS
  42. // freopen("1.in", "r", stdin);
  43. cin >> t;
  44. while(t --)
  45. solve();
  46. return 0;
  47. }

Codeforces Round 916 (Div. 3)(A~E2)的更多相关文章

  1. Codeforces Round #535 (Div. 3) 题解

    Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...

  2. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  8. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  10. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. svn把文件日期设置为最后提交的时间

    在使用svn进行checkout或update时,我想让文件的日期为提交那时的日期,这要怎样做? 说明:我是在windows下使用TortoiseSVN进行操作的 方法1.修改config [misc ...

  2. 从零开始配置 vim(15)——状态栏配置

    vim 下侧有一个状态栏,会显示当前打开的文件等一系列内容,只是我们很少去关注它.而且原生的vim也支持对状态栏进行自定义.这篇文章主要介绍如何自定义状态栏 设置状态栏 我们可以采用 set stat ...

  3. 第三届人工智能,大数据与算法国际学术会议 (CAIBDA 2023)

    第三届人工智能,大数据与算法国际学术会议 (CAIBDA 2023) ​ 大会官网:http://www.caibda.org/ 大会时间:2023年6月16-18日 大会地点:中国郑州 截稿日期:2 ...

  4. 淘宝一面:“说一下 Spring Boot 自动装配原理呗?”

    本文已经收录进 Github 95k+ Star 的Java项目JavaGuide .JavaGuide项目地址 : https://github.com/Snailclimb/JavaGuide . ...

  5. 书写自动智慧文本分类器的开发与应用:支持多分类、多标签分类、多层级分类和Kmeans聚类

    书写自动智慧文本分类器的开发与应用:支持多分类.多标签分类.多层级分类和Kmeans聚类 文本分类器,提供多种文本分类和聚类算法,支持句子和文档级的文本分类任务,支持二分类.多分类.多标签分类.多层级 ...

  6. 从零构建医疗领域知识图谱的KBQA问答系统:其中7类实体,约3.7万实体,21万实体关系。

    从零构建医疗领域知识图谱的KBQA问答系统:其中7类实体,约3.7万实体,21万实体关系. 项目效果 以下两张图是系统实际运行效果: 1.项目运行方式 运行环境:Python3 数据库:neo4j 预 ...

  7. C/C++ 操作数组与指针笔记

    指针数组: #include <stdio.h> #include <stdlib.h> #include <string.h> void PrintInt() { ...

  8. jetbrains 系列 terminal history 设置

    之前的版本中 jetbrains 的 terminal 使用的是 ~/.zsh_history, 改版后使用的不是一个 history, 就会出现在 iterm2 中使用的 command, 在 py ...

  9. 面试谈薪4点博弈策略,将20k谈到28k

    薪资谈判本质上是一种博弈,无论是表面谈得好还是实质上谈得好,都需要掌握一些策略 面试薪资怎么谈,您目前的薪资是20k,如果您想要提高到28k,那么请花两分钟看完以下内容.薪资谈判本质上是一种博弈,无论 ...

  10. Cygwin,在windows中使用linux命令

    习惯了 linux 命令的快捷操作,使用 winodws 的 shell 感觉效率非常低下,于是开始搜寻工具支持. 刚开始搜到的是 GnuWin32,但是它已经停止更新维护了,于是找到了 Cygwin ...