# 二分答案 扑克牌

``` 1 program hehe;
2 var
3  n,m,i,j:longint;
4  c:array[0..50] of longint;
5
6   function min(a,b:longint):longint;
7   begin
8    if a>b then exit(b);
9    exit(a);
10   end;
11
12   function ok(a:longint):boolean;
13   var
14    f,t:longint;
15   begin
16    t:=min(a,m);
17    for f:=1 to n do
18    begin
19     if c[f]<a then
20     t:=t-a+c[f];
21     if t<0 then exit(false);
22    end;
23    exit(true);
24   end;
25
26   function ef(l,r:longint):longint;
27   var
28    mid:longint;
29   begin
30    if l=r then exit(l);
31    mid:=(l+r)>>1;
32    if ok(mid+1) then
33    exit(ef(mid+1,r))
34    else exit(ef(l,mid));
35   end;
36
37 begin
39  for i:=1 to n do read(c[i]);
40  writeln(ef(1,maxlongint-1));
41 end.```

## 1816: [Cqoi2010]扑克牌

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1473  Solved: 566
[Submit][Status][Discuss]

3 4
1 2 3

## Sample Output

3

50%的数据满足：2 < = n < = 5, 0 < = m < = 10^ 6, 0< = ci < = 200
100%的数据满足：2 < = n < = 50, 0 < = m, ci < = 500,000,000。

## Source

[Submit][Status][Discuss]

## bzoj1816: [Cqoi2010]扑克牌(二分答案判断)

1816: [Cqoi2010]扑克牌 题目:传送门 题解: 被一道毒瘤题搞残了...弃了坑来刷刷水题 一开始还想复杂了...结果发现二分水过: 二分答案...然后check一下,joker肯定尽量用mid次,那么哪种牌不够就补(因为每次只能补一种,所以如果次数用完就return false) 代码: 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cmath> 5

## Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store

## HDU3081Marriage Match II(二分答案+并查集+最大流SAP)经典

Marriage Match II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2507    Accepted Submission(s): 856 Problem Description Presumably, you all have known the question of stable marriage match. A

## POJ 3080 Blue Jeans（后缀数组+二分答案）

[题目链接] http://poj.org/problem?id=3080 [题目大意] 求k个串的最长公共子串,如果存在多个则输出字典序最小,如果长度小于3则判断查找失败. [题解] 将所有字符串通过拼接符拼成一个串,做一遍后缀数组,二分答案,对于二分所得值,将h数组大于这个值的相邻元素分为一组,判断组内元素是否覆盖全字典,是则答案成立,对于答案扫描sa,输出第一个扫描到的子串即可. [代码] #include <cstdio> #include <cstring> #inclu

## 【二分答案+智障的字符串hash】BZOJ2946-[Poi2000]公共串(Ranklist倒一达成!!!!!)【含hash知识点】

[题目大意] 给出几个由小写字母构成的单词,求它们最长的公共子串的长度. [字符串hash的小笔记] hash[i]=(hash[i-1]*p+idx(s[i]))%mod,idx为映射值,一般a..z映射1..26: 习惯上,p取一个6到8位的素数即可,mod一般取大素数 1e9+7(1000000007)或1e9+9(1000000009). hash[i]=(hash[i-1]*p+idx(s[i]))%mod 表示第 i 个前缀的hash值,是一个hash的前缀和,那么,要求S[l…r]