Poker at bzoj1816

Source: Internet
Author: User

Description you have n kinds of cards, the number of the first type of cards is CI. There is also a special card: Joker, the number of which is M. You can use each of the cards to form a set of cards, you can also use a joker and other than a certain card to form a card each 1 sets of cards. For example, when n=3, there are 4 kinds of legitimate decks: {A-j,2,3}, {1,j,3}, {1,2,j}. Given n, m and CI, your task is to compose as many decks as possible. Each card can only be used in a set of cards (you may not use the card). The first line of input contains two integers n, m, the number of species and joker of the card. The second line contains n integer ci, which is the number of cards per card. Output outputs only one integer, which is the maximum number of decks that are composed. Sample Input3 4
1 2 3Sample Output3

Sample explanation
The input data indicate: There are 1 1, 2 2, 3 3, 4 joker. You can compose up to third officer decks: {1,j,3}, {j,2,3}, {J,2,3},joker has one remaining, and the rest of the cards run out.

Data range
50% data satisfies: 2 < = N < = 5, 0 < = m < = 10^ 6, 0< = ci < = 200
100% of the data meet: 2 < = n < =, 0 < = m, ci < = 500,000,000.
two points, check the answer, pay attention to the number of Joker to meet the requirementsdetermine the number of a group, each is not enough to use Joker to fill, if the number of Joker more than the number of groups, it is certainly not possible, because a group of up to one, if not exceeded the quantity, then any kind of card, in the absence of his time can use joker substitution, need him when there must be surplus , because joker in lieu of other cards when the need for him is certainly less than his number of cards, so as to ensure that the number of Joker satisfied with the necessary and sufficient conditions
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespacestd;Const intMAXN = the;intN,M,S,C[MAXN];voidinput () {CIN>>n>>m; S=0;  for(inti =1; I <= n;i++) {scanf ("%d",&C[i]); if(S < c[i]) s =C[i]; } s+=m;}BOOLCheckintt) {    intAdd =0;  for(inti =1; I <= n;i++){        if(T-c[i] >0) Add + = t-C[i]; if(T < add | | m < add)return false; }    return true;}voidDiv () {intLANs =0, rans =S,mans;  while(LANs <=rans) {Mans= (LANs + rans) >>1; if(check (mans)) {LANs= Mans +1; }Else{rans= Mans-1; }    }    if(Check (mans)) cout<<Mans; Elsecout<<mans-1;}intMain () {input ();    Div (); return 0;}
View Code

There is also an approach, in order to ensure that the number of Joker to meet the situation, to ensure that the previous demand is not more than the current number of cards can be, if the previous requirements can be satisfied, then the back of the demand before the need to meet

Prove:

Assuming that the number of the current decision card type is J, after supplementing such a card, does not meet the requirements of the card class for i,j before the demand for cards, the number of card groups T

J satisfies the requirement that there is J >= add

With Add + (T-J)-(t-i) > I

Add-j + i > I

J < add

Contradiction with the precondition of "J satisfies the requirement", the conclusion of the former paper is established

#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespacestd;Const intMAXN = the;intN,M,S,C[MAXN];voidinput () {CIN>>n>>m; S=0;  for(inti =1; I <= n;i++) {scanf ("%d",&C[i]); if(S < c[i]) s =C[i]; } s+=m;}BOOLCheckintt) {    intAdd = t-c[1]; if(Add <0) Add =0;  for(inti =2; I <= n;i++){        if(C[i] < add | | m < add)return false; Else{            if(T-c[i] >0) Add + = t-C[i]; }    }    if(M < add)return false; return true;}voidDiv () {intLANs =0, rans =S,mans;  while(LANs <=rans) {Mans= (LANs + rans) >>1; if(check (mans)) {LANs= Mans +1; }Else{rans= Mans-1; }    }    if(Check (mans)) cout<<Mans; Elsecout<<mans-1;}intMain () {input ();    Div (); return 0;}
View Code

Poker at bzoj1816

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.