51nod or 01 strings?

Source: Internet
Author: User

Given a 0-1 string s, the length is N, subscript starting from 0, to find a position k, satisfies 0<=k<=n, and substring s[0..k-1] 0 of the number and substring s[k. N-1] The number of 1 is equal. Attention:

(1) If k = 0, s[0..k-1] is treated as an empty string (2) If k = N, s[k. N-1] as a blank string (3) If there are more than one K value, the loss of any one can (4) if there is no such k value, please output-1 think for a while, found that there is no-1 case, is a pit, assuming 0-k-1 x 1,k,n-1 has y 1, then 0-k-1 k-x 0,k-x= Y so k=x+y, which means the answer equals 1 of the number.

51nod or 01 strings?

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.