2015noip Bucket Landlord

Source: Internet
Author: User

Bucket Landlord Title Description

Niuniu recently got hooked on a poker game called the Landlord. A bucket landlord is a poker game that uses spades, hearts, plum blossoms, square pieces of a to K plus a total of 54 cards of the king's size. In the bucket landlord, the size of the card is based on the digital representation of the following:3<4<5<6<7<8<9<10<j<q<k<a<2< Xiao Wang < king, And the color does not affect the size of the card. In each game, a second hand is made up of n cards. Each time the player can play according to the prescribed card type, first of all to light their own hand to win the game.

Now, cattle and cows just want to know, for their own group of hands, the minimum number of times required to play the cards can be light. Please help him to solve the problem.

It is important to note that the players in the subject can be shot each time the card type and the general landlords similar and slightly different.

The specific rules are as follows:

Input output Format input format:

The first line contains 2 positive integer tn separated by spaces, indicating the number of groups of hands and the number of cards per group.

Next T set of data, each set of data n rows, a non-negative integer per line of Aibi represents a card, where AI signs of the digital, BI represents the color of the card, the middle with a space separated. In particular, we use one of the digital a,11 said Digital j,12 said digital q,13 mean digital K, spades, hearts, plum, square slices respectively with 1-4 to express; Xiao Wang's expression method is 01, the King's expression method is 02.

Output format:

A total of T-lines, one integer per line, indicating the minimum number of times to hit the first hand.

Input and Output Sample input example:
1 87 48 49 110 411 15 11 41 1

Sample output:
3
Input Sample:
1 1712 34 32 35 410 23 312 20 11 310 16 212 111 35 212 42 27 2
Sample output:
6
Description

Example 1 description

There are 1 groups of hands, including 8 cards: Square 7, Square 8, Spades 9, Fang Pian 10, Spades J, Spades 5, square A and spades a. Can be played by Tanshong (Square 7, Square 8, Spades 9, Square 10, Spades J), a single card (spades 5) and a pair of cards (spades A and square a) within 3 times to light.

For different test points, we agreed that the size of the hand group T and the number of n is as follows:

Data assurance: All hand cards are randomly generated.

Analytical

Obviously, the color and the answer is irrelevant, ignoring TA is good, enumerate each possible straight, in the request for ANS will be able to take the card processing.

#include <cstdio>#include<cstring>using namespacestd;intn,t,s[ the];intans,a,b;intMinintAintb) {returnA>b?b:a;}voidDfsintNow ) {    if(Now>ans)return; intS1,s2,s3,s4; S1=s2=s3=s4=0;  for(intI=1; i<= -; i++)if(s[i]==1) s1++;//Statistics single card and the number of cards;     for(intI=1; i<= -; i++)if(s[i]==2) s2++;  for(intI=1; i<= -; i++)if(s[i]==4) {S4++; if(s1>=2) s1-=2;//Four can take as many bands as possible;        Else if(s2>=2) s2-=2; Else if(s2>=1) s2--; }     for(intI=1; i<= -; i++)if(s[i]==3) {S3++; if(s1>=1) s1--;//three belts;        Else if(s2>=1) s2--; } ans=min (ans,now+s1+s2+s3+S4); intJ;  for(intI=1; i<=8; i++) {//There is a case of Tanshong;         for(j=i;j<= A; j + +) {S[j]--; if(s[j]<0) Break; if(j-i>=4) DFS (now+1); }        if(j== -) j--;//backtracking;         while(j>=i) s[j--]++; }     for(intI=1; i<=Ten; i++) {//a case of double CIS;         for(j=i;j<= A; j + +) {S[j]-=2; if(s[j]<0) Break; if(j-i>=2) DFS (now+1); }        if(j== -) j--;//backtracking;         while(j>=i) s[j--]+=2; }     for(intI=1; i<= One; i++) {//There is a case of three straight children;         for(j=i;j<= A; j + +) {S[j]-=3; if(s[j]<0) Break; if(j-i>=1) DFS (now+1); }        if(j== -) j--;//backtracking;         while(j>=i) s[j--]+=3; }}intMain () {scanf ("%d%d",&t,&N);  while(t--) {memset (s),0,sizeof(s)); Ans= at;  for(intI=1; i<=n;i++) {//will A, 2, king, Xiao Wang put to the last;scanf"%d%d",&a,&b); if(a==0) s[ -]++; if(a==1) s[ A]++; if(a==2) s[ -]++; if(a>=3) s[a-2]++; } DFS (0); printf ("%d\n", ans); }    return 0;}
View Code

2015noip Bucket Landlord

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.