Codeforces_442_A
Posted 冷暖知不知
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #442 (Div. 2)
Codeforces Round #442 A Alex and broken contest字符串/常量数组/string类
Codeforces Round #442 (Div. 2) B. Nikita and string
Codeforces Round #442 (Div. 2) 877E - Danil and a Part-time Job dfs序+线段树