图见:http://codeforces.com/problemset/problem/343/B
巧妙!
将红上蓝下记为1,红下蓝上记为-1,压栈,相同相消,最后栈中无元素即可以分开=
1 #include<stdio.h> 2 #include<stack> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 char str[100005]; 7 stack<char>s; 8 int main() 9 { 10 int i,len; 11 scanf("%s",str); 12 len=strlen(str); 13 while (!s.empty()) s.pop(); 14 for (i=0;i<len;i++) 15 if (s.empty()) s.push(str[i]); 16 else{ 17 if (s.top()==str[i]) s.pop(); 18 else s.push(str[i]); 19 } 20 if (s.empty()) printf("Yes\n"); 21 else printf("No\n"); 22 }