首页 > 代码库 > Codeforces_442_A

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

 

Codeforces_442_A