国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

HDU1528-二分圖最小點(diǎn)覆蓋

2019-11-08 19:33:28
字體:
供稿:網(wǎng)友

Card Game Cheater

Time Limit: 2000/1000 MS (java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1880    Accepted Submission(s): 1038PRoblem DescriptionAdam and Eve play a card game using a regular deck of 52 cards. The rules are 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 in a row on the table. Adam’s cards are numbered from 1 to k from his left, and Eve’s cards are numbered 1 to k from her right (so Eve’s i:th card is opposite Adam’s i:th card). The cards are turned face up, and points are 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 two, a four beats a three and a two, etc. An ace beats every card except (possibly) another ace.If the two i:th cards have the same value, then the suit determines who wins: hearts beats all other suits, spades beats all suits except hearts, diamond beats only clubs, and clubs does not beat any suit. For example, the ten of spades beats the ten of diamonds but not the Jack of clubs. This ought to be a game of chance, but lately Eve is winning most of the time, and the reason is that she has started to use marked cards. In other Words, she knows which cards Adam has on the table before he turns them face up. Using this information she orders her own cards so that she gets as many points as possible.Your task is to, given Adam’s and Eve’s cards, determine how many points Eve will get if she plays optimally.  InputThere will be several test cases. The first line of input will contain a single positive integer N giving the number of test cases. After that line follow the test cases.Each test case starts with a line with a single positive integer k <= 26 which is the number of cards each player gets. The next line describes the k cards Adam has placed on the table, left to right. The next line describes the k cards Eve has (but she has not yet placed them on the table). A card is described by two characters, the first one being its value (2, 3, 4, 5, 6, 7, 8 ,9, T, J, Q, K, or A), and the second one being its suit (C, D, S, or H). Cards are separated by white spaces. So if Adam’s cards are the ten of clubs, the two of hearts, and the Jack of diamonds, that could be described by the lineTC 2H JD OutputFor each test case output a single line with the number of points Eve gets if she picks the optimal way to arrange her cards on the table. Sample Input
31JDJH25D TC4C 5H32H 3H 4H2D 3D 4D Sample Output
112 

題目大意

                 給你和你朋友一人n張牌,你知道你朋友的出牌順序,問你怎么安排你的出牌順序才能使你的得分最高,輸出最高得分,兩張牌如果點(diǎn)數(shù)相同則按花色,如果都相同都不得分,具體見題目描述

題目思路:

                  這題其實(shí)就是田忌賽馬的變形體,可以用貪心做,也可以用二分圖做,這里我用的是二分圖,首先我們考慮怎么建圖,我們知道最后是要你的得分最高,所以如果你的牌的大于他的牌那么你可以連一條邊,你的牌為一個(gè)集合,他的牌為一個(gè)集合,最后的模型就是選取最少的點(diǎn)使得所有邊的至少一個(gè)端點(diǎn)被選中,即最小點(diǎn)覆蓋模型,而最小點(diǎn)覆蓋就是最大匹配,所以我們進(jìn)行最大匹配的答案就是我們要求的

AC代碼:

#include<cstring>#include<cstdio>const int maxn = 30;bool vis[maxn],mp[maxn][maxn];int link[maxn];int com[127];int n;bool dfs(int u){    for(int i=1;i<=n;i++){        if(!vis[i]&&mp[u][i]){            vis[i]=true;            if(link[i]==-1||dfs(link[i])){                link[i]=u;                return true;            }        }    }    return false;}int main(){    com['H'-'1']=4,com['S'-'1']=3,com['D'-'1']=2,com['C'-'1']=1;   //預(yù)處理牌的大小    com['1'-'1']=1,com['2'-'1']=2,com['3'-'1']=3,com['4'-'1']=4;    com['5'-'1']=5,com['6'-'1']=6,com['7'-'1']=7,com['8'-'1']=8;    com['9'-'1']=9,com['T'-'1']=10,com['J'-'1']=11,com['Q'-'1']=12;    com['K'-'1']=13,com['A'-'1']=14;    int t;scanf("%d",&t);    while(t--){        scanf("%d",&n);        memset(link,-1,sizeof(link));        memset(mp,false,sizeof(mp));        char str[30][5];        for(int i=1;i<=n;i++){            scanf("%s",str[i]);        }        for(int i=1;i<=n;i++){            char ch[5];            scanf("%s",ch);            for(int j=1;j<=n;j++){                if(com[ch[0]-'1']>com[str[j][0]-'1']||com[ch[0]-'1']==com[str[j][0]-'1']&&com[ch[1]-'1']>com[str[j][1]-'1'])                        mp[i][j]=true;            }        }        int ans = 0;        for(int i=1;i<=n;i++){            memset(vis,false,sizeof(vis));            if(dfs(i))ans++;        }        printf("%d/n",ans);    }    return 0;}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 吴忠市| 博兴县| 毕节市| 松江区| 西城区| 凭祥市| 吴桥县| 普安县| 中宁县| 罗甸县| 平顶山市| 杭锦后旗| 会同县| 新兴县| 山阳县| 临潭县| 迭部县| 驻马店市| 乌拉特前旗| 广宗县| 蕲春县| 长宁县| 吉安县| 荥阳市| 遵义市| 车险| 鄯善县| 安塞县| 镇宁| 商丘市| 奇台县| 麟游县| 昌都县| 廉江市| 漳州市| 贺州市| 罗平县| 饶平县| 奎屯市| 宁远县| 镇远县|