HDU 4930 Fighting the Landlords(暴力枚舉+類比)

來源:互聯網
上載者:User

標籤:style   http   color   os   io   for   ar   代碼   

HDU 4930 Fighting the Landlords

題目連結

題意:就是題中那幾種牌型,如果先手能一步走完,或者一步讓後手無法管上,就贏

思路:先枚舉出兩個人所有可能的牌型的最大值,然後再去判斷即可

代碼:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;struct Player {    int rank[15];} p1, p2;int t, hash[205], cnt[(1<<20)], vis[20];char a[25], b[25];int bitcount(int x) {    int ans = 0;    while (x) {ans += (x&1);x >>= 1;    }    return ans;}void add(int num, Player &p) {    if (num == 2) {if (vis[14] && vis[15]) {    p.rank[7] = 14;    return;}    }    if (num == 5) {int a = 0, b = 0;for (int i = 15; i >= 1; i--) {    if (vis[i] == 3) a = i;    if (vis[i] == 2) b = i;}if (a && b) {    p.rank[5] = max(p.rank[5], a);}return;    }    for (int i = 15; i >= 1; i--) {if (num == 4 && vis[i] == 4) {    p.rank[7] = max(p.rank[7], i);    return;}if (num == 4 && vis[i] == 3) {    p.rank[4] = max(p.rank[4], i);    return;}if (num == 6 && vis[i] == 4) {    p.rank[6] = max(p.rank[6], i);    return;}if (vis[i] == num) {    p.rank[num] = max(p.rank[num], i);    return;}    }}void build(char *a, Player &p) {    memset(p.rank, 0, sizeof(p.rank));    int n = strlen(a);    int maxs = (1<<n);    memset(vis, 0, sizeof(vis));    for (int i = 0; i < maxs; i++) {if (cnt[i] > 6) continue;memset(vis, 0, sizeof(vis));for (int j = 0; j < n; j++) {    if (i&(1<<j)) {vis[hash[a[j]]]++;    }}add(cnt[i], p);    }}bool solve() {    int n = strlen(a);    if (n == 4) {if (p1.rank[7]) return true;    }    if (n <= 6) {if (p1.rank[n]) return true;    }    if (p1.rank[7] && p2.rank[7]) return p1.rank[7] > p2.rank[7];    if (p1.rank[7] && !p2.rank[7]) return true;    if (!p1.rank[7] && p2.rank[7]) return false;    for (int i = 1; i < 7; i++) {if (p1.rank[i] > p2.rank[i]) return true;    }    return false;}int main() {    for (int i = 0; i < (1<<20); i++)cnt[i] = bitcount(i);    for (int i = 3; i <= 9; i++)hash[i + '0'] = i - 2;    hash['T'] = 8; hash['J'] = 9; hash['Q'] = 10; hash['K'] = 11;    hash['A'] = 12; hash['2'] = 13; hash['X'] = 14; hash['Y'] = 15;    scanf("%d", &t);    while (t--) {scanf("%s%s", a, b);build(a, p1);build(b, p2);if (solve()) printf("Yes\n");else printf("No\n");    }    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.