zoukankan      html  css  js  c++  java
  • bzoj1816: [Cqoi2010]扑克牌

    题目链接

    bzoj1816: [Cqoi2010]扑克牌

    题解

    还是挺妙的
    一套牌只能用一张Joker,那么贪心是不对的
    若能够组成k套牌,那么joker一定有种方法在k套牌中出现<=1次
    那么,二分套数,检验joker够不够用

    代码

    /*
    还是挺妙的
    若能够组成k套牌,那么joker一定有种方法在k套牌中出现<=1次 
    那么 
    二分套数,检验joker够不够用
    */
    #include<cstdio> 
    #include<cstring> 
    #include<algorithm> 
    inline int read() {
         int x = 0,f = 1;
         char c = getchar(); 
         while ( c < '0' || c > '9')c = getchar(); 
         while(c <= '9' &&c >= '0')x = x*10 + c- '0',c = getchar() ; 
         return x ; 
    } 
    int n,m;  
    int c[79]; 
    bool check(int x) { 
        int ned = std::min(x,m); 
        int mx = 0,cmx= 0 ; 
        for(int i = 1;i <= n;++ i) {
            if(c[i] < x) ned -= x - c[i]; 
            if(ned < 0) return false; 
        } 
        return true; 
    } 
    int main() {  
        n = read(),m = read(); 
        for(int i = 1;i <= n;++ i) c[i] = read(); 
        int l = 0,r = 1000000007; 
        int ans = 0;
        while(l <= r) {
            int mid = l + r >> 1; 
            if(check(mid)){ ans = mid;l = mid + 1; } 
            else r = mid-  1; 
        } 
        printf("%d
    ",ans); 
        return 0; 
    } 
    
  • 相关阅读:
    Mysql分布式事务
    Mysql锁
    Mysql事务隔离级别
    java 资源监控
    Mysql子查询
    javaWeb四大域对象
    KVM 迁移
    KVM 虚拟化
    网络基础
    系统简单启动过程
  • 原文地址:https://www.cnblogs.com/sssy/p/9276739.html
Copyright © 2011-2022 走看看