BZOJ1816: [Cqoi2010]扑克牌

1816: [Cqoi2010]扑克牌

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1170  Solved: 430
[Submit][Status]

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。

HINT

Source

题解:

妈蛋,一道水题看了半天。。。

二分+判定即可。。。

代码:

 1 #include<cstdio>
 2 
 3 #include<cstdlib>
 4 
 5 #include<cmath>
 6 
 7 #include<cstring>
 8 
 9 #include<algorithm>
10 
11 #include<iostream>
12 
13 #include<vector>
14 
15 #include<map>
16 
17 #include<set>
18 
19 #include<queue>
20 
21 #include<string>
22 
23 #define inf 1000000000
24 
25 #define maxn 500+100
26 
27 #define maxm 500+100
28 
29 #define eps 1e-10
30 
31 #define ll long long
32 
33 #define pa pair<int,int>
34 
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36 
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38 
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40 
41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
42 
43 using namespace std;
44 
45 inline ll read()
46 
47 {
48 
49     ll x=0,f=1;char ch=getchar();
50 
51     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
52 
53     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
54 
55     return x*f;
56 
57 }
58 ll n,m,a[55];
59 inline bool check(ll x)
60 {
61     ll t=min(m,x);
62     for1(i,n)
63     {
64         if(a[i]<x)
65         {
66             t-=x-a[i];
67             if(t<0)return 0;
68         }
69     }
70     return 1;
71 }
72 
73 int main()
74 
75 {
76 
77     freopen("input.txt","r",stdin);
78 
79     freopen("output.txt","w",stdout);
80 
81     n=read();m=read();
82     for1(i,n)a[i]=read();
83     int l=0,r=inf,mid;
84     while(l<=r)
85     {
86         mid=(l+r)>>1;
87         if(check(mid))l=mid+1;else r=mid-1;
88     }
89     printf("%d\n",r);
90 
91     return 0;
92 
93 }
View Code

 

 

posted @ 2014-09-15 11:00  ZYF-ZYF  Views(230)  Comments(0Edit  收藏  举报