Codeforces Round #622 (Div. 2) 题解和我的分析
首先下午场非常适合中国人,开心
A
三种食物有个数限制,上菜,每次上菜跟以前的样式不能一样(食物的种类及个数各不相同),且每种食物最多用一次,问最多能上几次
对a,b,c排序,然后枚举上菜种类就可以了,注意最多能上7盘菜
#include<bits/stdc++.h>
#define LL long long
#define maxn 100010
using namespace std; int d[][] = {{, , }, {, , }, {, , }, {, , }, {, , }, {, , }, {, , }}; int main(){
int T;
cin >> T;
while(T--){
int a, b, c;
cin >> a >> b >> c;
if(a < b){
swap(a, b);
}
if(a < c){
swap(a, c);
}
if(b < c){
swap(b, c);
}
int ans = ;
for(int i = ; i < ; ++i){
if(a >= d[i][] && b >= d[i][] && c >= d[i][]){
ans++;
a = a - d[i][];
b = b - d[i][];
c = c - d[i][];
}
}
cout << ans << endl;
}
return ;
}
B
就是有两场比赛,每场每个人都有一个独特的得分(从1到n),问给定分数最高排名跟最低排名(如果并列就按下算)
没有太多好说的,分析下可以知道第一个数是a+b-n+1,第二个数是a+b-1,注意让他们在1-n之间即可
#include<bits/stdc++.h>
#define LL long long
#define maxn 100010
using namespace std; int main(){
int T;
cin >> T;
while(T--){
int n, a, b;
cin >> n >> a >> b;
if(a + b < n){
cout << << " " << min(a + b - , n) << endl;
}
else{
cout << min(a + b - n + , n) << " " << min(a + b - , n) << endl;
}
}
return ;
}
C1 and C2
这个题的简单版本可以很轻松的暴力,这里主要说说C2的单调栈做法
首先这个a在建完之后一定有个峰值,在他的两边依次下降,那么我们怎么快速统计呢?可以用单调栈来做这个题
首先从1到n,如果栈不空且栈中元素大于当前元素,那么出栈一个数,否则结束,接下来我们统计如果这个点是峰值,左面的最大值
记录栈顶元素,如果栈空,则说明先前元素必须都得是当前元素,否则左边的最大值应该是从当前元素到栈顶元素全变为当前元素的总和加上栈顶元素做峰值的最大值
从1到n进行完一遍后,再从n到1进行一遍就易统计出右面的最大值
然后每个元素做峰值,序列总和最大值应该是左边+右面-当前元素的值,找到峰值之后,这个题便迎刃而解了
#include<bits/stdc++.h>
#define LL long long
#define maxn 500010
using namespace std; stack<int> st; LL use1[maxn], use2[maxn], a[maxn]; LL cl[maxn], rl[maxn]; signed main(){
int n;
cin >> n;
for(int i = ; i <= n; ++i){
cin >> a[i];
}
memset(use1, , sizeof use1);
memset(use2, , sizeof use2);
for(int i = ; i <= n; ++i){
if(st.empty() || a[st.top()] <= a[i]){
use1[i] = a[i] + use1[i - ];
st.push(i);
}
else{
while(!st.empty() && a[st.top()] > a[i]){
st.pop();
}
if(st.empty()){
use1[i] = a[i] * i;
}
else{
use1[i] = a[i] * (i - st.top()) + use1[st.top()];
}
st.push(i);
}
}
while(!st.empty()){
st.pop();
}
for(int i = n; i > ; --i){
if(st.empty() || a[st.top()] <= a[i]){
use2[i] = a[i] + use2[i + ];
st.push(i);
}
else{
while(!st.empty() && a[st.top()] > a[i]){
st.pop();
}
if(st.empty()){
use2[i] = a[i] * (n - i + );
}
else{
use2[i] = a[i] * (st.top() - i) + use2[st.top()];
}
st.push(i);
}
}
LL ans = ;
int id = -;
for(int i = ; i <= n; ++i){
//cout << use1[i] << " " << use2[i] << endl;
if(use1[i] + use2[i] - a[i] > ans){
ans = use1[i] + use2[i] - a[i];
id = i;
}
}
//cout << id << endl;
for(int i = id; i <= n; ++i){
if(a[i] < a[i + ]){
a[i + ] = a[i];
}
}
for(int i = id; i > ; --i){
if(a[i] < a[i - ]){
a[i - ] = a[i];
}
}
for(int i = ; i <= n; ++i){
cout << a[i] << " ";
}
cout << endl;
return ;
}
D跟E过的人不超过三位数,就不在考虑范围内了,这场难度偏难,虽然我也没想到打成这个b样子分还能涨一点
Codeforces Round #622 (Div. 2) 题解和我的分析的更多相关文章
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version)(单调栈,递推)
Codeforces Round #622 (Div. 2) C2. Skyscrapers (hard version) 题意: 你是一名建筑工程师,现给出 n 幢建筑的预计建设高度,你想建成峰状, ...
- Codeforces Round #622 (Div. 2) B. Different Rules(数学)
Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...
- Codeforces Round #622 (Div. 2) A. Fast Food Restaurant(全排列,DFS)
Codeforces Round #622 (Div. 2) A. Fast Food Restaurant 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
随机推荐
- leetcode 390. 消除游戏
{20-01-29 19:22} class Solution { public int lastRemaining(int n) { return help(n); } public static ...
- 块级元素、行内元素、display属性
块级元素 特点: 总是以一个块的形式表现出来,占领一整行.若干同级块元素会从上之下依次排列(使用float属性除外). 可以设置高度.宽度.各个方向的margin以及各个方向的padding. 当宽度 ...
- CSS3-背景(background-image、background-size、background-origin、background-clip)
CSS3中新的背景属性:background-image.background-size.background-origin.background-clip 背景图片:background-image ...
- 设计模式课程 设计模式精讲 17-2 模板方法模式coding
1 代码演练 1.1 代码演练1 1.2 代码演练2(后端课程子类运用钩子方法,加入写手记的方法) 1.3 代码演练3(前端有多个子类,有得需要写手记,有得不需要写,如何实现?) 1 代码演练 1.1 ...
- jeDate日期控件精确到秒
案例下载 链接: https://pan.baidu.com/s/1m7eEW6K6Bt1t-0OjVY_Wxw 密码: xmei <script type="text/javascr ...
- 学术Essay写作简单且稳定的架构解析
学术essay写作(academic writing),无论是论文还是专著,间架要稳固,才有可读性,才有说服力. 稳,有几个应然特征:部块(parts)关联紧密:部块不外生枝叶:部块之间没有杂质干扰. ...
- 【快学springboot】5.全局异常捕获,异常流处理业务逻辑
前言 上一篇文章说到,参数校验,往往需要和全局的异常拦截器来配套使用,使得返回的数据结构永远是保持一致的.参数异常springboot默认的返回结构: { "timestamp": ...
- ORM常用字段及查询
目录 ORM常用字段及参数 创建表 ORM常用字段 ORM字段参数 ORM表关系创建 ForeignKey OneToOneField ManyToManyField 多对多三种创建方式 单表查询 q ...
- input不显示边框
参考:https://www.cnblogs.com/mmykdbc/p/6200963.html input{ border: none; outline: none; }
- helm基本用法
一.helm命令 helm search #关键字搜索charts helm pull #压缩下载chart到本地,可以使用--untar下载解压) helm install #部署chart到kub ...