zoukankan      html  css  js  c++  java
  • hiho 1326 有序01字符串

    时间限制:10000ms
    单点时限:1000ms
    内存限制:256MB

    描述

    对于一个01字符串,你每次可以将一个0修改成1,或者将一个1修改成0。那么,你最少需要修改多少次才能把一个01串 S 变为有序01字符串(有序01字符串是指满足所有0在所有1之前的01串)呢?

    输入

    第一行是一个整数 T,代表测试数据的组数。(1 ≤ T ≤ 10)

    以下T行每行包含一个01串 S 。(1 ≤ |S| ≤ 1000)

    输出

    对于每组测试数据输出最少需要修改的次数。

    样例输入
    3
    000111
    010001
    100000 
    样例输出
    0
    1
    1

    枚举所有状态。

    比如长度为4的字符串最终可能的状态为:

    0000

    0001

    0011

    0111

    1111

    所以n^2可以解决

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/7/2 23:20:23
    File Name     :hiho1326.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    int a[maxn];
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int t;
        char s[maxn];
        cin>>t;
        while(t--){
            scanf("%s",s+1);
            int n=strlen(s+1);
            int Min=INF;
            for(int i=0;i<=n+1;i++){
                int ans=0;
                for(int j=1;j<=i;j++){
                    if(s[j]!='0')ans++;
                }
                for(int j=i+1;j<=n;j++){
                    if(s[j]!='1')ans++;
                }
                Min=min(ans,Min);
            }
            cout<<Min<<endl;
        }
        return 0;
    }
  • 相关阅读:
    [转]网站架构收集 朱燚:
    SQLServer 2005 海量数据解决方案 分区表 朱燚:
    【轻松一下】女朋友的保健作用 朱燚:
    A tip when running javascript dynamically 朱燚:
    【组图】地震前线归来心中的震撼 朱燚:
    系统自动启动程序之十大藏身之所 朱燚:
    [轻松一下]90%的男人想作的事情 朱燚:
    JavaScript的9个陷阱及评点 朱燚:
    【转】c++中的sizeof 朱燚:
    PG数据库中相关操作
  • 原文地址:https://www.cnblogs.com/pk28/p/5636392.html
Copyright © 2011-2022 走看看