A过水,不讲

题解 CF1077B 【Disturbed People】

  • 这题就是个显而易见的贪心可是我考场上差点没想出来
  • 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉
  • 从左到右扫一遍,每次如果遇到一户被打扰的人家就ans++,然后把它右边的灯关掉
  • 然后就做完了
  1. # include <bits/stdc++.h>
  2. int a[101];
  3. int main()
  4. {
  5. int n;
  6. int ans = 0;
  7. scanf("%d", &n);
  8. for(int i = 1; i <= n; i++)
  9. scanf("%d", &a[i]);
  10. for(int i = 2; i <= n - 1; i++)
  11. {
  12. if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1)
  13. ans++, a[i + 1] = 0;//关右边的灯
  14. }
  15. printf("%d\n", ans);
  16. return 0;
  17. }

题解 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]\)时满足条件
  • 判断一下就好了
  1. # include <bits/stdc++.h>
  2. # define ll long long
  3. struct p
  4. {
  5. int id;
  6. ll x;
  7. };
  8. p a[200001];
  9. int cmp(p x, p y){return x.x < y.x;}
  10. std::vector<int> vec;
  11. int main()
  12. {
  13. int n;
  14. ll sum = 0;
  15. scanf("%d", &n);
  16. for(int i = 1; i <= n; i++)
  17. scanf("%d", &a[i].x), a[i].id = i, sum += a[i].x;
  18. std::sort(a + 1, a + n + 1, cmp);
  19. for(int i = 1; i <= n; i++)
  20. {
  21. if(i != n)//情况1
  22. {
  23. if(sum - a[n].x - a[i].x == a[n].x)
  24. vec.push_back(a[i].id);
  25. }
  26. else //情况2
  27. {
  28. if (sum - a[n - 1].x - a[i].x == a[n - 1].x)
  29. vec.push_back(a[i].id);
  30. }
  31. }
  32. if(vec.size())
  33. {
  34. printf("%d\n", vec.size());
  35. for(int i = 0; i < vec.size(); i++)
  36. printf("%d ", vec[i]);
  37. }
  38. else
  39. printf("0");
  40. return 0;
  41. }

题解 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

  1. #include <bits/stdc++.h>
  2. int n, k;
  3. int a[200010], ans[200010];
  4. int s[200010];
  5. std::queue<int> st;
  6. int check(int x)
  7. {
  8. while(!st.empty())
  9. st.pop();
  10. for(int i = 1; i <= 200000; i++)
  11. for(int j = s[i] / x; j; j--)//能加的全部加进去
  12. st.push(i);
  13. if(st.size() >= k)//满足条件
  14. {
  15. for(int i = 1; i <= k; i++)
  16. ans[i] = st.front(), st.pop();
  17. return true;
  18. }
  19. return false;
  20. }
  21. int main()
  22. {
  23. scanf("%d%d", &n, &k);
  24. for (int i = 1; i <= n; i++)
  25. scanf("%d", &a[i]), s[a[i]]++;
  26. int l = 0, r = 200001;
  27. while (l < r)//二分
  28. {
  29. int mid = (l + r + 1) >> 1;
  30. if (check(mid))
  31. l = mid;
  32. else
  33. r = mid - 1;
  34. }
  35. for (int i = 1; i <= k; i++)
  36. printf("%d ", ans[i]);
  37. return 0;
  38. }

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. scratch少儿编程第一季——08、特效我也会

    各位小伙伴大家好: 上期我们学习了外观模块的角色切换,今天我们继续学习外观模块的其他指令. 首先来看特效指令. 这里我们克隆了三只小猫作对比,将颜色特效增加25. 这个指令除了颜色特效还有很多其他的特 ...

  2. uboot-的start.S详细注解及分析

    原文地址:uboot-的start.S详细注解及分析 作者:zhouyg11 大多数bootloader都分为stage1和stage2两部分,u-boot也不例外.依赖于CPU体系结构的代码(如设备 ...

  3. java运算符那些事

    && 逻辑与 &&先运算&&左边的算式,如果为假,则直接停止,后面不管有多少运算式都不再运算,如果为真则继续判断后面的式子,只有所有的条件全部成立,才会 ...

  4. C# 注册windows 服务

    sc delete CCGSQueueService sc create CCGSQueueService binpath= "D:\DKX4003\services\CCGSQueueSe ...

  5. ...:ES6中扩展运算符(spread)和剩余运算符(rest)详解

    1.扩展运算符(spread) demo1:传递数据代替多个字符串的形式 let test= function(a,b,c){ console.log(a); console.log(b); cons ...

  6. 关于linux中关在共享文件的NFS 提示错误解决办法

    0. 查看挂载情况命令 : findmnt 1. 如果在客户机上遇到如下这样的提示错误,有可能的原因是因为没有安装nfs-utils   只需要yum install nfs-utils   就解决了 ...

  7. Spring AOP编程经验总结

    编程范式概览:面向过程,面向对象,函数式编程,事件驱动编程,面向切面等, AOP是什么? Spring AOP是采用面向切面编程的编程范式,而非编程语言,它只能解决特定问题,而非所有问题,它与OOP不 ...

  8. 根目录/缺少执行权限x产生的两种错误

    Linux根目录缺少x权限,产生的两个错误: 以root用户执行systemctl命令报权限相关问题 [root@hps2 ~]# systemctl stop hps-manager * (pktt ...

  9. 异步网络编程aiohttp的使用

    aiohttp的使用 aiohttp Asynchronous HTTP Client/Server for asyncio and Python. Supports both Client and ...

  10. java8大基本类型

    文章转载自:Java的8种基本数据类型 请阅读原文. 关于Java的8种基本数据类型,其名称.位数.默认值.取值范围及示例如下表所示: 序号 数据类型 位数 默认值 取值范围 举例说明 1 byte( ...