Codeforces 443A Borya and Hanabi(暴力)

來源:互聯網
上載者:User

標籤:style   http   color   width   os   for   

題目連結:Codeforces 443A Borya and Hanabi

題目大意:有若干個牌,每張牌有花色和數字兩個值,現在問說至少詢問多少次才能區分出所有的牌,每次詢問可以確定一種花色牌的位置,或者是一種數字牌的位置。

解題思路:暴力枚舉需要問的花色和數字,210,然後枚舉兩兩判斷是否可以被區分。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 105;int n, l[N], r[N];inline int cal (char ch) {    if (ch == ‘B‘)        return 0;    else if (ch == ‘Y‘)        return 1;    else if (ch == ‘W‘)        return 2;    else if (ch == ‘G‘)        return 3;    else if (ch == ‘R‘)        return 4;    return -1;}int bit (int i) {    return 1<<i;}int bitCount (int x) {    return x == 0 ? 0 : bitCount(x/2) + (x&1);}bool judge (int s) {    for (int i = 0; i < n; i++) {        for (int j = i + 1; j < n; j++) {            if (l[i] == l[j]) {                if (r[i] != r[j] && (s&bit(r[i]+5)) == 0 && (s&bit(r[j]+5)) == 0)                    return false;            } else {                if ((s&bit(l[i])) || (s&bit(l[j])))                    continue;                if (r[i] != r[j] && ( (s&bit(r[i]+5)) || (s&bit(r[j]+5)) ))                    continue;                return false;            }        }    }    return true;}int main () {    char str[N];    scanf("%d", &n);    for (int i = 0; i < n; i++) {        scanf("%s", str);        l[i] = cal(str[0]);        r[i] = str[1] - ‘1‘;    }    int ans = 10;    for (int i = 0; i < (1<<10); i++) {        int cnt = bitCount(i);        if (cnt >= ans)            continue;        if (judge(i))            ans = cnt;    }    printf("%d\n", ans);    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.