码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • D - Project Planning--二分


    D - Project Planning

    Time Limit: 2 sec / Memory Limit: 1024 MB

    Score : 400400 points

    Problem Statement

    KEYENCE has NN departments, where A_iAi​ employees belong to the ii-th department (1 \leq i \leq N)(1≤i≤N). No employee belongs to multiple departments.

    The company is planning cross-departmental projects. Each project will be composed of exactly KK employees chosen from KK distinct departments.

    At most how many projects can be made? No employee can participate in multiple projects.

    Constraints

    • 1 \leq K \leq N \leq 2 \times 10^51≤K≤N≤2×105
    • 1 \leq A_i \leq 10^{12}1≤Ai​≤1012
    • All values in input are integers.

    Input

    Input is given from Standard Input in the following format:

    NN KK
    A_1A1​ A_2A2​ \ldots… A_NAN​
    

    Output

    Print the maximum possible number of projects.


    Sample Input 1 Copy

    Copy

    3 3
    2 3 4
    

    Sample Output 1 Copy

    Copy

    2
    

    There can be two projects, each composed of three employees from distinct departments.


    Sample Input 2 Copy

    Copy

    4 2
    1 1 3 4
    

    Sample Output 2 Copy

    Copy

    4
    

    Sample Input 3 Copy

    Copy

    4 3
    1 1 3 4
    

    Sample Output 3 Copy

    Copy

    2

    =========================================================================

    数据范围小的话优先队列贪心是很容易理解的。但本题需要二分,或许用到的这个结论是很普遍,需要特殊记住的计数问题,那就是n个小组,每组k个物体,要求组内不能重复,那么最终判定条件是所有小于等于n(大于n取等于n)的个数要 >= n*k,也就是说,只要数量够了,一定能构造出来不重复n个序列,很不好想或者去证明,只能说是一个计数结论罢了

     注意r太大会爆掉,故我们取r=1e18/k,再乘k的时候就不会爆掉了,当然128位也是很方便。

    题目没一般说明我们都是在1e18内获取答案的

    1. # include
    2. # include
    3. # include
    4. # include
    5. # include
    6. # include
    7. # include
    8. # include
    9. # include
    10. # include
    11. using namespace std;
    12. typedef __int128 ll;
    13. __int128 read(){
    14. __int128 x=0,f=1;
    15. char ch=getchar();
    16. while(!isdigit(ch)&&ch!='-')ch=getchar();
    17. if(ch=='-')f=-1,ch=getchar();
    18. while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    19. return f*x;
    20. }
    21. void print(__int128 x){
    22. if(x<0)putchar('-'),x=-x;
    23. if(x>9)print(x/10);
    24. putchar(x%10+'0');
    25. }
    26. ll a[200000+10];
    27. ll k,n;
    28. bool check(ll mid)
    29. {
    30. ll sum=0;
    31. for(int i=1;i<=n;i++)
    32. {
    33. sum+=min(mid,a[i]);
    34. }
    35. return mid*k<=sum;
    36. }
    37. int main()
    38. {
    39. n=read();
    40. k=read();
    41. for(int i=1;i<=n;i++)
    42. {
    43. a[i]=read();
    44. }
    45. ll l=1,r=1e18;
    46. while(l<=r)
    47. {
    48. ll mid=(l+r)>>1;
    49. if(check(mid))
    50. l=mid+1;
    51. else
    52. r=mid-1;
    53. }
    54. print(r);
    55. return 0;
    56. }

  • 相关阅读:
    解决使用WebTestClient访问接口报[185c31bb] 500 Server Error for HTTP GET “/**“
    陈可之国画|《同杯万古尘》
    java毕业设计——基于java+JSP+J2EE的户籍管理系统设计与实现——户籍管理系统
    Java中的内存泄漏及其排查方法
    含文档+PPT+源码等]精品基于SSM的奶茶店信息管理系统[包运行成功]程序设计源码计算机毕设
    肖sir__设计测试用例方法之状态迁移法05_(黑盒测试)
    项目进展(九)-完善ADS1285代码
    【React】单页面应用限制多开登录
    图卷积网络(Graph Convolutional Network, GCN)
    音频处理:Acon Digital Acoustica Premium Mac
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126116484
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号