标签:
提示:100%的数据中,N<=50.
50%的数据中,N<=20.
【题解】
额。。就是随便乱搞啦,学网上的搞了个deque双端队列
C++就是好STL好
1 #include<cstdio> 2 #include<deque> 3 using namespace std; 4 deque<char> str[3]; 5 int main() { 6 int n[3]; 7 for (int i=0;i<3;++i) { 8 scanf("%d",&n[i]); 9 if(!n[i]) continue; 10 char c=getchar(); 11 while(c<‘A‘||c>‘Z‘) c=getchar(); 12 while(c>=‘A‘&&c<=‘Z‘) str[i].push_back(c),c=getchar(); 13 } 14 while(str[0].size()&&str[1].size()&&str[2].size()&&str[0].front()==str[1].front()&&str[1].front()==str[2].front()) { 15 str[0].pop_front(); str[1].pop_front(); str[2].pop_front(); 16 } 17 int tot=str[1].size()+str[0].size()+str[2].size(); 18 int ans=tot; 19 for (int i=0;i<3;++i) 20 for (int j=i+1;j<3;++j) { 21 int k=0; 22 for (;k<min(str[i].size(),str[j].size())&&str[i][k]==str[j][k];++k); 23 int res=tot-str[i].size()-str[j].size(); 24 res+=k; 25 res+=str[i].size()-k+str[j].size()-k; 26 ans=min(ans,res); 27 } 28 printf("%d\n",ans); 29 }
[BZOJ 1789] [BZOJ 1830] [AHOI 2008] Necklace Y型项链
标签:
原文地址:http://www.cnblogs.com/TonyNeal/p/bzoj1789.html