CF #460 div2-c-Greedy

Source: Internet
Author: User


Problem-solving ideas: This condition is very loose, so as long as always find, find can not find so far stop, and then all match found 1 there is still left, then is not feasible. So that's a good thing to do with set.


#include <bits/stdc++.h> using namespace std;
typedef long Long LL;
const int MX = 2E5+10;
int N,M,Q,NUMBER[MX];
Char STR[MX];
Set <int> st[2];
Vector <int> VEC[MX];
    int main () {scanf ("%s", str+1);
    TOP1 = TOP2 = 0;
    int Len = strlen (str+1), num,top;
        for (int i=1;i<=len;i++) {num = str[i]-' 0 ';
    St[num].insert (i);
    } top = num = 0;
        while (St[0].size ()) {Vec[top].push_back (*st[0].begin ());
        St[0].erase (St[0].begin ());
        int id = 1;
            while (1) {Auto it = St[id].lower_bound (Vec[top].back ()); 
                if (It==st[id].end ()) {if (!id) St[1].insert (Vec[top].back ()), Vec[top].erase (--vec[top].end ());
            Break
            } vec[top].push_back (*it);
        St[id].erase (IT), id ^= 1;
    } top++;
    } if (St[1].size ()) return puts ("1");
    printf ("%d\n", top); for (int i=0;i<top;i++) {printf ("%d", vec[I].size ());
        for (int j=0;j<vec[i].size (); j + +) {printf ("%d", vec[i][j]);
    } puts ("");
} return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.