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 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
随机推荐
- c++中的运算符重载operator1(翁恺c++公开课[30]学习笔记)
运算符重载规则: 只有已经存在的运算符才能被重载,不能自己制造一个c++中没有的运算符进行重载 重载可以在类或枚举类型内进行,也可以是全局函数,但int.float这种已有的类型内是不被允许的 不能二 ...
- Linux centosVMware 配置Tomcat监听80端口、配置Tomcat虚拟主机、Tomcat日志
一.配置Tomcat监听80端口 关闭tomcat报错 [root@davery src]# /usr/local/tomcat/bin/shutdown.sh 重装tomcat即可 vim /usr ...
- [swscaler @ ...] deprecated pixel format used, make sure you did set range correctly
我自己在使用如下函数进行转换时报的错 int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int sr ...
- css怎样让元素显示指定的宽高比
.father { width: 100% } .child {; padding-bottom: 20%; background: green; overflow: hidden; } <bo ...
- phpcms安装与使用
安装完wamp(或phpstudy)之后,将phpcms的安装文件复制入C:\wamp\www(或C:\phpStudy\PHPTutorial\WWW)文件夹下: 打开phpcms_v9_UTF8\ ...
- unity 骨骼 蒙皮
https://blog.csdn.net/weixin_44350205/article/details/100551233 https://www.jianshu.com/p/d5e2870eb3 ...
- MySQL实现主从复制功能
环境说明 centos7.3.MySQL5.7 前言 MySQL安装参考之前的文章https://www.jianshu.com/p/452aa99c7476有讲解. ...
- PAT A1025 pat ranking
有n个考场,每个考场都有若干数量个考生,现给出各个考场中考生的准考证号和分数,要求将所有考生的分数从高到低排序,并输出 #include<iostream> #include<str ...
- python 开启http服务并下载文件
Python <= 2.3python -c "import SimpleHTTPServer as s; s.test();" 8000 Python >= 2.4p ...
- SeekBar和RatingBar的基本使用方法
SeekBar: main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...