Codeforces Round #521 (Div.3)题解
A过水,不讲
题解 CF1077B 【Disturbed People】
- 这题就是个显而易见的贪心可是我考场上差点没想出来
- 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉
- 从左到右扫一遍,每次如果遇到一户被打扰的人家就ans++,然后把它右边的灯关掉
- 然后就做完了
# include <bits/stdc++.h>
int a[101];
int main()
{
int n;
int ans = 0;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for(int i = 2; i <= n - 1; i++)
{
if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1)
ans++, a[i + 1] = 0;//关右边的灯
}
printf("%d\n", ans);
return 0;
}
题解 CF1077C 【Good Array】
- 个人觉得这题比B还水
- 先排下序,扫一遍\(1-n\)
- 对于每个数\(i\),如果\(i \neq n\),则当\(\sum_{j=1}^na[j]-a[i]=2*a[n]\)时满足条件
- 不然要是\(i = n\)的话,当\((\sum_{j=1}^na[j])-a[n]=2*a[n-1]\)时满足条件
- 判断一下就好了
# include <bits/stdc++.h>
# define ll long long
struct p
{
int id;
ll x;
};
p a[200001];
int cmp(p x, p y){return x.x < y.x;}
std::vector<int> vec;
int main()
{
int n;
ll sum = 0;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i].x), a[i].id = i, sum += a[i].x;
std::sort(a + 1, a + n + 1, cmp);
for(int i = 1; i <= n; i++)
{
if(i != n)//情况1
{
if(sum - a[n].x - a[i].x == a[n].x)
vec.push_back(a[i].id);
}
else //情况2
{
if (sum - a[n - 1].x - a[i].x == a[n - 1].x)
vec.push_back(a[i].id);
}
}
if(vec.size())
{
printf("%d\n", vec.size());
for(int i = 0; i < vec.size(); i++)
printf("%d ", vec[i]);
}
else
printf("0");
return 0;
}
题解 CF1077D 【Cutting Out】
昨晚刚打的场,感触深刻啊
昨天打的时候死命WA16结果才发现16是\(n=k\)的的点
\(rp--,rating-=inf\)
好了说正事
这道题我们可以枚举删除次数,发现满足单调性,果断二分
check扫一遍\(1-200000\),对于每个数i,每次将序列长度加上(i出现的次数/当前check的删除次数),如果序列长度\(\ge k\)就return true;否则return false;
在二分时处理一下答案即可
其实用不着queue,但已经STL依赖症了qwq
#include <bits/stdc++.h>
int n, k;
int a[200010], ans[200010];
int s[200010];
std::queue<int> st;
int check(int x)
{
while(!st.empty())
st.pop();
for(int i = 1; i <= 200000; i++)
for(int j = s[i] / x; j; j--)//能加的全部加进去
st.push(i);
if(st.size() >= k)//满足条件
{
for(int i = 1; i <= k; i++)
ans[i] = st.front(), st.pop();
return true;
}
return false;
}
int main()
{
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), s[a[i]]++;
int l = 0, r = 200001;
while (l < r)//二分
{
int mid = (l + r + 1) >> 1;
if (check(mid))
l = mid;
else
r = mid - 1;
}
for (int i = 1; i <= k; i++)
printf("%d ", ans[i]);
return 0;
}
Codeforces Round #521 (Div.3)题解的更多相关文章
- 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 #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- 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 #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
随机推荐
- 『Python基础』第4节:基础数据类型初识
本节只是对基础数据类型做个简单介绍, 详情会在之后慢慢介绍 什么是数据类型? 我们人类可以分清数字与字符串的区别, 可是计算机不能. 虽然计算机很强大, 但在某种程度上又很傻, 除非你明确告诉它数字与 ...
- BZOJ4516 SDOI2016生成魔咒(后缀自动机)
本质不同子串数量等于所有点的len-parent树上父亲的len的和.可以直接维护. #include<iostream> #include<cstdio> #include& ...
- (一)weblogic11g的安装配置
一.安装 找到weblogic安装包,小编这里用的是wls1034_win32.exe版本,双击打开 完成后运行快速启动,打开快速启动界面,配置weblogic.如果没有打开,还可以在开始菜单中找到q ...
- SQL优化中的重要概念:事务
原文:SQL优化中的重要概念:事务 sql 优化和事务有关系? 从表面上看,让sql跑的更快,似乎和事务这个概念没什么联系,但是关系数据库中最重要的2个概念就是 关系.事务. 关系,对应到sql中,是 ...
- luogu题解 P3950部落冲突--树链剖分
题目链接 https://www.luogu.org/problemnew/show/P3950 分析 大佬都用LCT,我太弱只会树链剖分 一个很裸的维护边权树链剖分题.按照套路,对于一条边\(< ...
- “df: cannot read table of mounted file systems”.
“df: cannot read table of mounted file systems”.“df -l” returned an error: “df: cannot read table of ...
- 新学WEB前端
介绍一点关于我对学习前端的一些学习经验和遇到的问题! 1.坚持 现在编码技术更新的速度日新月异,并且对于纯英文字母的代码来说,我们不是长时间接触并且记忆的话,对于一些难一些的标签和属性是非常容易忘记的 ...
- MVC模板页使用
这里我们要做一个公共的模板,样式如下: 内容 ·asp.net mvc如何创建模板??1.在/Views/Shared/中右键-添加-视图 2.重命名为”HeadLayout”,勾选”创建为分部视图” ...
- DNSMaper 一款子域名枚举与地图标记工具
DNSMaper DNSMaper拥有与众多子域名枚举工具相似的功能,诸如域传送漏洞检测,子域名枚举,IP地址获取 文件说明├── dnsmaper.py(核心代码)├── dnsmapper.png ...
- 2.Storm集群部署及单词统计案例
1.集群部署的基本流程 2.集群部署的基础环境准备 3.Storm集群部署 4.Storm集群的进程及日志熟悉 5.Storm集群的常用操作命令 6.Storm源码下载及目录熟悉 7.Storm 单词 ...