Hdoj title 1528 Card Game cheater (two-figure minimum point overlay)

Source: Internet
Author: User

Card Game CheaterTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1357 Accepted Submission (s): 722


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 is the number of the cards each player gets. 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

TC 2H JD

Outputfor 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 Input
31jdjh25d tc4c 5h32h 3H 4h2d 3D 4D

Sample Output
112

Sourcenorthwestern Europe 2004
Recommend8600 | We have carefully selected several similar problems for you:1507 1533 1530 1526 2768

The title means to a deck of cards, the size of the points from 2-a,t represents the largest 10,a. Then the four colors are C, D, S, H, if the points are the same c<d<s

AC Code

 #include <stdio.h> #include <string.h>int a[1010],b[1010],map[1010][1010] , Link[1010],vis[1010],n;int Fun (char *s) {int ans;if (s[0]== ' T ') ans=10;elseif (s[0]== ' J ') ans=11;elseif (s[0]== ' Q ') ans =12;elseif (s[0]== ' K ') ans=13;elseif (s[0]== ' A ') ans=14;elseans=s[0]-' 0 '; if (s[1]== ' C ') Ans=ans*10+1;elseif (s[1]== ' D ') Ans=ans*10+2;elseif (s[1]== ' s ') Ans=ans*10+3;elseif (s[1]== ' H ') Ans=ans*10+4;return ans;} int dfs (int x) {int i;for (i=1;i<=n;i++) {if (!vis[i]&&map[x][i]) {vis[i]=1;if (link[i]==-1| | DFS (Link[i])) {Link[i]=x;return 1;}}} return 0;} int main () {int t;scanf ("%d", &t), while (t--) {int i,j;scanf ("%d", &n), and for (i=1;i<=n;i++) {char s[10];scanf ("% S ", s); A[i]=fun (s);} for (i=1;i<=n;i++) {char s[10];scanf ("%s", s); B[i]=fun (s);} memset (map,0,sizeof (map)); for (i=1;i<=n;i++) {for (j=1;j<=n;j++) {if (A[i]<b[j]) {map[i][j]=1;}}} memset (link), int ans=0;for (i=1;i<=n;i++) {memset (vis,0,sizeof (VIS)), if (Dfs (i)) ans++;} printf ("%d\n", ans);}} 


Hdoj title 1528 Card Game cheater (two-figure minimum point overlay)

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.