码迷,mamicode.com
首页 > Web开发 > 详细

https://vjudge.net/contest/356507#problem/C

时间:2020-02-11 19:28:07      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:sig   get   ble   mes   getchar   bsp   main   情况下   har   

00001111
在前i-1个全相等的情况下,对于位置i,如果a[i]!=a[i-1],要么把前i-1个反转,要么把n-(i-1)位置的反转。按位处理,每次从这两个情况里面取最大值。最后从这些最大值里取最小值就是答案

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#define inf 2147483647
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(int i=a;i<=b;++i)

using namespace std;
int n,cnt,ans;
int a[N];
char c[N];
void in(int &x){
    int y=1;char c=getchar();x=0;
    while(c<0||c>9){if(c==-)y=-1;c=getchar();}
    while(c<=9&&c>=0){ x=(x<<1)+(x<<3)+c-0;c=getchar();}
    x*=y;
}
void o(int x){
    if(x<0){p(-);x=-x;}
    if(x>9)o(x/10);
    p(x%10+0);
}

signed main(){
    cin>>(c+1);
    n=(int)strlen(c+1);
    For(i,2,n){
        if(c[i]!=c[i-1]) a[++cnt]=max(i-1,n-(i-1));
    }
    ans=n;
    For(i,1,cnt) ans=min(ans,a[i]);
    o(ans);
    return 0;
}

 

https://vjudge.net/contest/356507#problem/C

标签:sig   get   ble   mes   getchar   bsp   main   情况下   har   

原文地址:https://www.cnblogs.com/war1111/p/12296002.html

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