zoukankan      html  css  js  c++  java
  • Codeforces_442_A_枚举

    http://codeforces.com/problemset/problem/442/A

    想想成5*5的图,一共能划10条线,枚举2^10次即可。

    判断每种情况是否符合条件的方法,若存在点,被线穿过的状态一样,当时不是同一个点,则不符合。

    #include <cstdio>
    #include<iostream>
    #include<string>
    #include<cstring>
    using namespace std;
    int color[105],num[105],temp[105],count[1050] = {0};
    string s;
    int main()
    {
        int n;
        cin >> n;
        for(int i = 1;i <= n;i++)
        {
            cin >> s;
            if(s[0] == 'R') color[i] = 0;
            else if(s[0] == 'G') color[i] = 1;
            else if(s[0] == 'B') color[i] = 2;
            else if(s[0] == 'Y') color[i] = 3;
            else if(s[0] == 'W') color[i] = 4;
            num[i] = s[1]-'1';
        }
        int ans = 10;
        for(int i = 0;i < (1<<10);i++)
        {
            memset(temp,0,sizeof(temp));
            if(i)
                count[i] = count[i>>1]+(i&1);
            for(int j = 1;j <= n;j++)
            {
                if((i>>color[j])&1)
                    temp[j] |= 1<<color[j];
                if((i>>(num[j]+5))&1)
                    temp[j] |= 1<<(num[j]+5);
                for(int k = 1;k < j;k++)
                {
                    if(temp[j] == temp[k] && (color[k] != color[j] || num[j] != num[k]))
                        goto there;
                }
            }
            ans = min(ans,count[i]);
            there:
            continue;
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    Java Number & Math 类
    excel小技巧-转置(表的横向纵向倒过来)
    excel小技巧-提取填充
    excel小技巧-分列
    Java switch case语句
    if...else
    12.15个人总结
    12.9个人总结
    11.29个人总结
    11.25日个人总结
  • 原文地址:https://www.cnblogs.com/zhurb/p/5872547.html
Copyright © 2011-2022 走看看