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 题意: 你是餐馆老板,虽然只会做三道菜,上菜时还有个怪癖:一位客人至少上一道菜,且一种菜最 ...
随机推荐
- EC20的指令
AT+QURCCFG="urcport","usbat" :当设置在主串口时且用主串口进行AT交互时开机会收到一串状态的信息,默认USBAT就不会 AT+IPR ...
- iOS 开发之 开发一款自己的美颜相机
以前在公司做项目时很少遇到对相机.图片进行处理的(非公司业务),只是偶尔上传,裁剪,预览下.近期自己准备写个相机应用,把图片处理的这些技术细节整理下.包含美颜相机,图片美化,简单拼图,艺术拼图等主要模 ...
- Oracle 提取数据表信息
参考: https://www.progress.com/blogs/jdbc-tutorial-extracting-database-metadata-via-jdbc-driver http:/ ...
- jqGrid 多选复选框 编辑列 方法事件
参考:https://blog.csdn.net/zsq520520/article/details/53375284?locationNum=8&fps=1
- 回顾PHP:第一章:PHP基础语法(2)
十.PHP常量和变量——用常量限制用户跳过某些文件(重要) 十.1常量在代码中定义.书写方式: define(常量名,常量值) 注:1.常量值只能为标量 2.常量名可以小写,但是通常大写 3.常量名可 ...
- json序列化(重要)
(1)同(2)public JsonResult JsonUserGet() { DataSet ds = Web_User.P_LG_User_Get(nUserId); return Json(J ...
- JS监听video视频播放时间
采用原生时间监听element.addEventListener(event, function, useCapture) //监听播放时间 var video = document.getEleme ...
- 对于java多态的总结
父类引用指向子类对象是Java比较基础的概念.Java作为一门面向对象编程的语言,调用对象是在编程中经常用到的.尚学堂李老师为大家详细说明这一概念. 例如父类Animal,子类Cat,Dog.其中An ...
- django的404,500错误自定义页面的配置
django404,500错误自定义页面: 1.设置settings文件 DEBUG = False ALLOWED_HOSTS = ['127.0.0.1', 'localhost']或者ALLOW ...
- Android之系统自带的文字外观设置及实际显示效果图
android:textAppearance xml布局里面设置文字的外观: 如“android:textAppearance=“?android:attr/textAppearanceLargeI ...