A

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

#include <bits/stdc++.h>
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f using namespace std;
const int N = 1e5+10;
int t; void solve()
{
int n; string str;
cin >> n >> str;
map<char,int>cnt;
rep(i,0,str.size()-1)
{
cnt[str[i]]++;
}
int ans = 0;
for(auto x:cnt)
{
int num=x.first-'A'+1;
if(x.second>=num) ans++;
}
cout << ans << endl;
} int main()
{
IOS
// freopen("1.in", "r", stdin);
cin >> t;
while(t --)
solve();
return 0;
}

B

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

#include <bits/stdc++.h>
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f using namespace std;
const int N = 1e5+10;
int t,a[60]; void solve()
{
int n, k, cnt=1; cin >> n >> k;
rep(i,1,n) a[i]=0; rep(i,n-k,n) a[cnt++] = i;
fep(i,n-k-1,1) a[cnt++] = i;
rep(i,1,n) cout << a[i] << ' ';
cout << endl;
} int main()
{
IOS
// freopen("1.in", "r", stdin);
cin >> t;
while(t --)
solve();
return 0;
}

C

#include <bits/stdc++.h>
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f using namespace std;
const int N = 2e5+10;
int t;
int a[N], b[N], s[N];
void solve()
{
int n, k; cin >> n >> k;
rep(i,1,n) s[i]=0;
rep(i,1,n) cin >> a[i], s[i] = s[i-1]+a[i];
rep(i,1,n) cin >> b[i];
int maxx=-INF, ans=-INF;
rep(i,1,min(k,n))
{
maxx=max(maxx, b[i]);
int cur=s[i]; cur+=max(0,k-i)*maxx;
ans=max(cur,ans);
}
cout << ans << endl;
} int main()
{
IOS
// freopen("1.in", "r", stdin);
cin >> t;
while(t --)
solve();
return 0;
}

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]\)

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

#include <bits/stdc++.h>
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f using namespace std;
const int N = 2e5+10;
int t, a[N], b[N], c[N];
int la[N], ra[N], lb[N], rb[N], lc[N], rc[N]; void solve()
{
int n; cin >> n;
rep(i,0,n+1) la[i]=0,ra[i]=0,lb[i]=0,rb[i]=0,lc[i]=0,rc[i]=0;
rep(i,1,n) cin >> a[i];
rep(i,1,n) cin >> b[i];
rep(i,1,n) cin >> c[i];
rep(i,1,n) la[i] = max(la[i-1], a[i]);
fep(i,n,1) ra[i] = max(ra[i+1], a[i]);
rep(i,1,n) lb[i] = max(lb[i-1], b[i]);
fep(i,n,1) rb[i] = max(rb[i+1], b[i]);
rep(i,1,n) lc[i] = max(lc[i-1], c[i]);
fep(i,n,1) rc[i] = max(rc[i+1], c[i]);
ll ans=0;
rep(i,2,n-1)
{
ll maxx=0;
maxx = max(maxx, (ll)a[i] + lb[i-1] + rc[i+1]);
maxx = max(maxx, (ll)a[i] + lc[i-1] + rb[i+1]);
maxx = max(maxx, (ll)b[i] + la[i-1] + rc[i+1]);
maxx = max(maxx, (ll)b[i] + lc[i-1] + ra[i+1]);
maxx = max(maxx, (ll)c[i] + la[i-1] + rb[i+1]);
maxx = max(maxx, (ll)c[i] + lb[i-1] + ra[i+1]);
ans = max(ans, maxx);
}
cout << ans << endl;
} int main()
{
IOS
// freopen("1.in", "r", stdin);
cin >> t;
while(t --)
solve();
return 0;
}

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]\)值较大的这一列进行操作

#include <bits/stdc++.h>
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(register int i = (a); i >= (b); --i)
#define ls p<<1
#define rs p<<1|1
#define PII pair<int, int>
#define ll long long
#define ull unsigned long long
#define db double
#define endl '\n'
#define debug(a) cout<<#a<<"="<<a<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3f3f3f3f using namespace std;
const int N = 2e5+10;
int t;
struct wy
{
ll x, y, sum;
}a[N];
bool cmp(wy a, wy b)
{
return a.sum > b.sum;
}
void solve()
{
int n; cin >> n;
rep(i,1,n) cin >> a[i].x;
rep(i,1,n) cin >> a[i].y, a[i].sum=a[i].x+a[i].y;
sort(a+1,a+1+n, cmp);
ll ans=0;
rep(i,1,n)
{
if(i&1) ans += a[i].x-1;
else ans -= a[i].y-1;
}
cout << ans << endl;
} int main()
{
IOS
// freopen("1.in", "r", stdin);
cin >> t;
while(t --)
solve();
return 0;
}

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. 【转载】基于Tablestore Timeline的IM(即时通讯)消息系统架构 - 架构篇

    本文原作者:木洛,阿里云高级技术专家,内容有优化和修订,感谢原作者.原文链接:https://developer.aliyun.com/article/698301 IM全称是『Instant Mes ...

  2. 7.2 Windows驱动开发:内核注册并监控对象回调

    在笔者上一篇文章<内核枚举进程与线程ObCall回调>简单介绍了如何枚举系统中已经存在的进程与线程回调,本章LyShark将通过对象回调实现对进程线程的句柄监控,在内核中提供了ObRegi ...

  3. 东吴名贤传<二>薛综传

     古典记载 吴录曰:其先齐孟尝君封於薛.秦灭六国,而失其祀,子孙分散.汉祖定天下,过齐,求孟尝后,得其孙陵.国二人,欲复其封.陵.国兄弟相推,莫適受,乃去之竹邑,因家焉,故遂氏薛.自国至综,世典州郡, ...

  4. 《IDEA Plugin 开发手册》• 小傅哥.pdf | 年前整理的最后一本PDF资料

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 为什么?写写快乐的热门文章不好吗! 从开始准备成体系的编写 IDEA Plugin ...

  5. 2024-01-31:用go语言,机器人正在玩一个古老的基于DOS的游戏, 游戏中有N+1座建筑,从0到N编号,从左到右排列, 编号为0的建筑高度为0个单位,编号为i的建筑的高度为H(i)个单位, 起

    2024-01-31:用go语言,机器人正在玩一个古老的基于DOS的游戏, 游戏中有N+1座建筑,从0到N编号,从左到右排列, 编号为0的建筑高度为0个单位,编号为i的建筑的高度为H(i)个单位, 起 ...

  6. Leetcode刷题第五天-二分法-回溯

    215:第k个最大元素 链接:215. 数组中的第K个最大元素 - 力扣(LeetCode) em~~怎么说呢,快速选择,随机定一个目标值,开始找,左边比目标小,右边比目标大,左右同时不满足时,交换左 ...

  7. 错误:tensorflow.python.framework.errors_impl.InvalidArgumentError: ValueError: attempt to get argmax of an empty sequence的解决方案

    近日,在使用Cascade R-CNN完成目标检测任务时,我在使用这个模型训练自己的数据集时出现了如下错误: 具体如以下截图所示: 详细错误如下所示: Traceback (most recent c ...

  8. webpack学习笔记(二)核心概念理解及基础配置

    上一篇文章 记录了 webpack 初次安装与基础使用,本篇则是记录一下如何使用webpack构建一个比较完整,基础的项目 1. webpack 的4个核心概念 入口(entry):选择项目构建的入口 ...

  9. 【Unity3D】选中物体描边特效

    1 前言 ​ 描边的难点在于如何检测和识别边缘,当前实现描边特效的方法主要有以下几种: ​ 1)基于顶点膨胀的描边方法 ​ 在 SubShader 中开 2 个 Pass 渲染通道,第一个 Pass ...

  10. MySQL表锁定处理

    研发要在一个ol_poster_sign表加字段,表比较大有400多万条,用gh-ost加字段时,在切换过程中一直报错: 无法完成最后的切换: INFO Magic cut-over table cr ...