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. 希尔伯特变换用于解调系统——以解调调频信号为例,FM Demodulation

    What's The Hilbert Transform 简单地说,希尔伯特变换的物理意义为:把信号的所有频率分量的相位推迟90度,这样原信号和变换后信号可以视为一组IQ正交信号,在数字域正交化,可以 ...

  2. js下载附件(文件时候),文件名一直不出现乱码

    if (lastUrl.name) { //我们后端很奇怪有时候是个对象属性,有时候是个string window.open(url + `?attname=${lastUrl.name}`); } ...

  3. 【4】配置和运行Opencv常见的一些问题总结,以及bug解决。

    相关文章: [1]windows下安装OpenCV(4.3)+VS2017安装+opencv_contrib4.3.0配置 [2]Visual Studio 2017同时配置OpenCV2.4 以及O ...

  4. 8.9 RDTSC时钟检测反调试

    RDTSC时钟检测同样可实现反调试检测,使用时钟检测方法是利用rdtsc汇编指令,它返回至系统重新启动以来的时钟数,并且将其作为一个64位的值存入EDX:EAX寄存器中,通过运行两次rdstc指令,然 ...

  5. ChatGPT 对接微信公众号技术方案实现!

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 9天假期写了8天代码和10篇文章,这个5.1过的很爽! 如假期前小傅哥的计划一样,这个假期开启 ...

  6. 解决Maven项目创建过慢问题

    在创建时弹出Proerties位置添加键值对: archetypeCatalog internal idea 常用快捷键 Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N ...

  7. 图解Java原理

    1:强制类型转换数据溢出 2:顺序结构的流程图 3:单if语句的流程图 4:标准if-else语句的流程图 5:扩展if-else语句的流程图 6:for循环流程图

  8. ABC 306

    前三题过水. D \(dp[i][j]\) 表示吃完前 \(i\) 个菜,胃的状况为 \(j\)(\(0\) 是健康,\(1\) 是不好)所获得的最大美味值. E 暴力的平衡树.用 multiset ...

  9. B3610 [图论与代数结构 801] 无向图的块 题解

    题目传送门 前言 本题解内容均摘自我的 Tarjan 学习笔记 . 解法 Tarjan 与无向图 无向图与割点(割顶) 在一个无向图中,不存在横叉边(因为边是双向的). 一个无向图中,可能不止存在一个 ...

  10. JS leetcode x 的平方根 题解分析

    壹 ❀ 引 这几天心情复杂,也不知道形容.做道题吧,其实是上周的题,一直没整理,比较巧的是,这也是我同学17年去PPTV面试时遇到的一题,题目来自leetcode69. x 的平方根,题目描述如下: ...