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 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
随机推荐
- TensorFlow基础二(Shape)
首先说明tf中tensor有两种shape,分别为static (inferred) shape和dynamic (true) shape,其中static shape用于构建图,由创建这个tenso ...
- JQuery 实现PPT效果,点跳目标页及翻页(待改进)
实现PPT效果 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...
- 第2节 Scala中面向对象编程:12、13、14、15、16、trait
6.4. Scala中面向对象编程之trait 6.4.1. 将trait作为接口使用 Scala中的trait是一种特殊的概念: 首先先将trait作为接口使用,此时的trait就与Java ...
- Codeforces Round #581 (Div. 2)D(思维,构造,最长非递减01串)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main ...
- python学习 —— seaborn、matplotlib、pandas、numpy package的混合使用
这里使用了Titanic Machine learning数据集,然后通过Seaborn的函数来拟合和绘制回归线,matplotlib进行可视化. 先来一个简单的测试: import pandas a ...
- 腾讯云服务器安装python3
一,开始安装python3 首先安装相关包,这里千万不能忽视,不然有什么不可预见的错误会很难受.其命令如下: yum install zlib-devel bzip2-devel openssl ...
- 获取SDWebImage的缓存大小并清除
// 获取SDWebImage的缓存大小 - (NSString *)cacheSizeFormat { NSString *sizeUnitString; float size = [SDWebIm ...
- 十七、java内存模型_JVM_JDK_类加载
1.Java内存模型 共享内存模型指的就是Java内存模型(简称JMM),JMM决定一个线程对共享变量的写入时,能对另一个线程可见.从抽象的角度来看,JMM定义了线程和主内存之间的抽象关系:线程之间的 ...
- 解题报告:luogu P1144 最短路计数
题目链接:P1144 最短路计数 很简单的一道\(dfs\),然而我又跑了一遍\(dij\)和排序,时间复杂度是\(O(nlog n)\) 注意:\(1\).搜索时向\(dis[j]=dis[cur] ...
- JDBC--批量处理
1.当需要成批插入或者更新记录时,可以采用Java的批量更新机制,这一机制允许多条语句一次性提交给数据库批量处理,这样可以提高处理速度. 2.JDBC的批量处理语句包括两个方法: --1)addBat ...