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

    Time Limit: 10 Sec  Memory Limit: 64 MB
    Submit: 2737  Solved: 1082
    [Submit][Status][Discuss]

    Description

    你有n种牌,第i种牌的数目为ci。另外有一种特殊的牌:joker,它的数目是m。你可以用每种牌各一张来组成一套牌,也可以用一张joker和除了某一种牌以外的其他牌各一张组成1套牌。比如,当n=3时,一共有4种合法的套牌:{1,2,3}, {J,2,3}, {1,J,3}, {1,2,J}。 给出n, m和ci,你的任务是组成尽量多的套牌。每张牌最多只能用在一副套牌里(可以有牌不使用)。

    Input

    第一行包含两个整数n, m,即牌的种数和joker的个数。第二行包含n个整数ci,即每种牌的张数。

    Output

    输出仅一个整数,即最多组成的套牌数目。

    Sample Input

    3 4
    1 2 3

    Sample Output

    3

    样例解释
    输入数据表明:一共有1个1,2个2,3个3,4个joker。最多可以组成三副套牌:{1,J,3}, {J,2,3}, {J,2,3},joker还剩一个,其余牌全部用完。

    数据范围
    50%的数据满足:2 < = n < = 5, 0 < = m < = 10^ 6, 0< = ci < = 200
    100%的数据满足:2 < = n < = 50, 0 < = m, ci < = 500,000,000。
     
    注意一张牌组,joker只能用一次
     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 
     5 int n,m;
     6 int c[55];
     7   
     8 bool check(int x)
     9 {
    10     int tmp=min(m,x);
    11     for(int i=1;i<=n;i++)
    12     {
    13         if(x>c[i]) tmp-=x-c[i];
    14         if(tmp<0) return false;
    15     }
    16     return true;
    17 }
    18   
    19 int main()
    20 {
    21     int left=1,right=2e9;
    22     scanf("%d%d",&n,&m);
    23     for(int i=1;i<=n;i++)
    24         scanf("%d",&c[i]);
    25     while(left<right)
    26     {
    27         int mid=(left+right)>>1;
    28         if(check(mid)) left=mid+1;
    29         else right=mid;
    30     }
    31     printf("%d",left-1);
    32     return 0;
    33 }
  • 相关阅读:
    java 测试 (junit+ junit 断言 + postman)
    junit 运行(eclipse + IDEA)
    junit 常用注解 + junit 断言详解
    工作周报模板
    spring boot tomcat 部署
    spring boot 集成JSP
    spring boot 集成 Mybatis,JPA
    JPA 常用注解
    员工年终绩效考核表模板
    2013 Noip提高组 Day1
  • 原文地址:https://www.cnblogs.com/InWILL/p/10051031.html
Copyright © 2011-2022 走看看