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个折扣的时候,你必须 ...
随机推荐
- scratch少儿编程第一季——08、特效我也会
各位小伙伴大家好: 上期我们学习了外观模块的角色切换,今天我们继续学习外观模块的其他指令. 首先来看特效指令. 这里我们克隆了三只小猫作对比,将颜色特效增加25. 这个指令除了颜色特效还有很多其他的特 ...
- uboot-的start.S详细注解及分析
原文地址:uboot-的start.S详细注解及分析 作者:zhouyg11 大多数bootloader都分为stage1和stage2两部分,u-boot也不例外.依赖于CPU体系结构的代码(如设备 ...
- java运算符那些事
&& 逻辑与 &&先运算&&左边的算式,如果为假,则直接停止,后面不管有多少运算式都不再运算,如果为真则继续判断后面的式子,只有所有的条件全部成立,才会 ...
- C# 注册windows 服务
sc delete CCGSQueueService sc create CCGSQueueService binpath= "D:\DKX4003\services\CCGSQueueSe ...
- ...:ES6中扩展运算符(spread)和剩余运算符(rest)详解
1.扩展运算符(spread) demo1:传递数据代替多个字符串的形式 let test= function(a,b,c){ console.log(a); console.log(b); cons ...
- 关于linux中关在共享文件的NFS 提示错误解决办法
0. 查看挂载情况命令 : findmnt 1. 如果在客户机上遇到如下这样的提示错误,有可能的原因是因为没有安装nfs-utils 只需要yum install nfs-utils 就解决了 ...
- Spring AOP编程经验总结
编程范式概览:面向过程,面向对象,函数式编程,事件驱动编程,面向切面等, AOP是什么? Spring AOP是采用面向切面编程的编程范式,而非编程语言,它只能解决特定问题,而非所有问题,它与OOP不 ...
- 根目录/缺少执行权限x产生的两种错误
Linux根目录缺少x权限,产生的两个错误: 以root用户执行systemctl命令报权限相关问题 [root@hps2 ~]# systemctl stop hps-manager * (pktt ...
- 异步网络编程aiohttp的使用
aiohttp的使用 aiohttp Asynchronous HTTP Client/Server for asyncio and Python. Supports both Client and ...
- java8大基本类型
文章转载自:Java的8种基本数据类型 请阅读原文. 关于Java的8种基本数据类型,其名称.位数.默认值.取值范围及示例如下表所示: 序号 数据类型 位数 默认值 取值范围 举例说明 1 byte( ...