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)题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. 『Python Web框架之Django』第几节: AJAX

    一. AJAX简介 AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步的Javascript和XML”.即使用Javascript语言与服务器进行异步交互, ...

  2. Django——关于项目开发遇到的一些小技巧

    目录 头像图片 js获取网站信息 js获取前端信息 Dj获取刚写入的数据的信息 js跳转新链接 头像图片对象的显示 在做到根据登陆ID决定用户头像的时候,加载静态文件的{% static ‘xxxxx ...

  3. Typora 的使用

    一. Typora的markdown语法 1.标题 使用简单的ctr+数字健,就可以快速完成各种级别的标题 #一阶标题 或者快捷键Ctrl+1 ##二阶标题 或者快捷键Ctrl+2 ##二阶标题 或者 ...

  4. TCP协议和UDP协议的对比【转】

    原文:https://blog.csdn.net/lzj2504476514/article/details/81454754 一.TCP协议的主要特点(1)TCP是面向连接的运输层协议:(2)每一条 ...

  5. 基于vue的购物车清单

    <!doctype html> <html> <head> <meta charset="utf-8"> <link rel= ...

  6. dockerfile构建nginx

    mkdir docker_demo cd docker_demo wget http://nginx.org/download/nginx-1.2.9.tar.gz vim Dockerfile FR ...

  7. <转载>c++中new一个二维数组

    原文连接 在c++中定义一个二维数组时有多种方式,下面是几种定义方式的说明:其中dataType 表示数据类型,如int  byte  long... 1.dataType (*num)[n] = n ...

  8. Nginx系列1.2:nginx-rtmp流媒体服务器添加权限认证(推流权限和播放权限)

    用到的工具:OBS Studio(推流).nginx-rtmp流媒体服务器.VLC(拉取流播放) Nginx系列1:ubuntu16.04编译出适合自己的nginx服务器 Nginx系列1.1:ubu ...

  9. Liunx-tail命令

    1. 实时刷新tail -f /var/log/messages 2. 实时刷新最新500条log tail -500f  /var/log/messages 3. tail -n 20 catali ...

  10. Reservoir Sampling 蓄水池采样算法

    https://blog.csdn.net/huagong_adu/article/details/7619665 https://www.jianshu.com/p/63f6cf19923d htt ...