Codeforces 443a Borya and Hanabi (violent)

Source: Internet
Author: User

Link: codeforces 443a Borya and Hanabi

There are several cards, each of which has two values: Color and number. Now I want to ask how many times at least to differentiate all cards, you can determine the position of a card or a digital card each time you ask.

Solution: The color and number that needs to be asked for brute-force enumeration, Which is 210. Then, the enumeration is used to determine whether it can be distinguished.

#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;}

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.