Card Game Cheater
Problem Descriptionadam and Eve play a card game using a regular deck of cards. The rules is simple. The players sit on opposite sides of a table, facing each other. Each player gets K-cards from the deck and, after looking at them, places the cards-face-down-a row on the table. Adam's cards is numbered from 1 to K from the he left, and Eve's cards is numbered 1 to K from she right (so Eve's i:th car D is opposite Adam's i:th card). The cards is turned face up, and points is awarded as follows (for each i∈{1, ..., k}):
If Adam's i:th card beats Eve's i:th card, then Adam gets one point.
If Eve ' s i:th card beats Adam's i:th card, then Eve gets one point.
A card with higher value always beats a card with a lower value:a three beats A, a four beats a three and a, etc. An ace beats every card except (possibly) another ace.
If The i:th cards has the same value, then the suit determines who wins:hearts beats all other suits, spades beats a ll suits except hearts, diamond beats only clubs, and clubs does no beat any suit.
For example, the ten of Spades beats the ten of diamonds and not the Jack of clubs.
This ought to being a game of chance, but lately Eve was winning most of the time, and the reason was that she had started to u Se marked cards. In other words, she knows which cards Adam have on the table before he turns them face up. Using This information she orders hers own cards so, she gets as many points as possible.
Your task is to, given Adam's and Eve's cards, determine how many points Eve would get if she plays optimally.
Inputthere'll be several test cases. The first line of input would contain a single positive integer N giving the number of test cases. After this line follow the test cases.
Each test case starts with a line with a single positive integer k <= which are the number of cards each player G Ets. The next line describes the K cards Adam have placed on the table and left to right. The next line describes the K cards Eve had (but she had not yet placed them on the table). A card is described by-characters, the first one being its value (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A), and the S Econd one being its suit (C, D, S, or H). Cards is separated by white spaces. So if Adam's cards is the ten of clubs, the both of the hearts, and the Jack of diamonds, that could is described by the line< /c0>
TC 2H JDOutputfor each test case output a single line with the number of points Eve gets if she picks the optimal-to arrange H ER cards on the table.
Sample input31jdjh25d tc4c 5h32h 3H 4h2d 3D 4D Sample Output112
#include <cstdio>#include<cctype>#include<cstring>#include<vector>#include<algorithm>#definePB Push_backusing namespacestd;BOOLcmpCharACharBB) { if(IsDigit (a)) {if(Isalpha (b))return 1; Else returna<b; } Else { if(IsDigit (b))return 0; Else { if(a=='T')return 1; Else if(a=='J') { if(b=='Q'|| b=='K'|| b=='A')return 1; Else return 0; } Else if(a=='Q') { if(b=='K'|| b=='A')return 1; Else return 0; } Else if(a=='K') { if(b=='A')return 1; Else return 0; } Else return 0; } }}structcard{CharVal,suit; BOOL operator< (Constcard& RHS)Const { if(Val!=rhs.val)returnCMP (val,rhs.val); Else { if(suit=='C')return 1; Else if(suit=='D') { if(rhs.suit=='S'|| rhs.suit=='H')return 1; Else return 0; } Else if(suit=='S') { if(rhs.suit=='H')return 1; Else return 0; } Else return 0; }}}c[2][ -];intk,link[ -],vis[ -];vector<int>g[ -];BOOLDfsintu) { for(intLen=g[u].size (), i=0; i<len;i++) { intv=G[u][i]; if(!Vis[v]) {Vis[v]=1; if(link[v]==-1||DFS (Link[v])) {Link[v]=u; return 1; } } } return 0;}intmatch () {intans=0; memset (Link,-1,sizeof(link)); for(intI=0; i<k;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i)) ans++; } returnans;}voidcreate_graph () { for(intI=0; i<k;i++) g[i].clear (); for(intI=0; i<k;i++) for(intj=0; j<k;j++) if(c[0][i]<c[1][j]) G[I].PB (j);intMain () {intT; scanf ("%d",&T); while(t--) {scanf ("%d",&k); for(intI=0; i<k;i++) {GetChar (); scanf ("%c%c", &c[0][i].val,&c[0][i].suit); } for(intI=0; i<k;i++) {GetChar (); scanf ("%c%c", &c[1][i].val,&c[1][i].suit); } create_graph (); printf ("%d\n", Match ()); } return 0;}
HDU 1528 Card Game cheater