首页 > 代码库 > BZOJ 3916 friends
BZOJ 3916 friends
暴力。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 2000050 using namespace std; char s[maxn]; int l; bool l_match() { int p1=1,p2=l/2+1,ret=0; while ((p1<=l/2) && (p2<=l)) { if (s[p1]!=s[p2]) {p2++;ret++;if (ret==2) return false;} if (s[p1]==s[p2]) {p1++;p2++;} } return true; } bool r_match() { int p1=1,p2=l/2+2,ret=0; while ((p1<=l/2+1) && (p2<=l)) { if (s[p1]!=s[p2]) {p1++;ret++;if (ret==2) return false;} if (s[p1]==s[p2]) {p1++;p2++;} } return true; } bool l_r_match() { for (int i=1;i<=l/2;i++) if (s[i]!=s[i+l/2+1]) return false; return true; } int main() { scanf("%d",&l); scanf("%s",s+1); if (!(l&1)) {printf("NOT POSSIBLE\n");return 0;} bool f1=l_match(),f2=r_match(); if ((!f1) && (!f2)) printf("NOT POSSIBLE\n"); else if (f1 && f2) { if (!l_r_match()) printf("NOT UNIQUE"); else for (int i=1;i<=l/2;i++) printf("%c",s[i]); printf("\n"); } else if (f1) { for (int i=1;i<=l/2;i++) printf("%c",s[i]); printf("\n"); } else { for (int i=l/2+2;i<=l;i++) printf("%c",s[i]); printf("\n"); } return 0; }
BZOJ 3916 friends
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。