码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 3916 friends

时间:2017-02-01 21:45:03      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:define   names   algorithm   ssi   not   als   algo   div   bsp   

暴力。

#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

标签:define   names   algorithm   ssi   not   als   algo   div   bsp   

原文地址:http://www.cnblogs.com/ziliuziliu/p/6360379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!