BZOJ3016 [Usaco2012 Nov]clumsy cows

Source: Internet
Author: User

Konjac Konjac or brush the water ... (Don't ask me why I have to write a question about this tea.)

Orz Sea tree: "Consider that each closing parenthesis must have a pair of opening parentheses before it, so the sum is recorded to the current position without the number of pairs of opening parentheses.

If negative, this means that a closing parenthesis must be turned into an opening parenthesis, that is, ans++ and sum+=2 (because a closing parenthesis is missing one more opening parenthesis).

The final plus one-second of the remaining pairs of open parentheses is the answer. "

1 /**************************************************************2 problem:30163 User:rausen4 language:c++5 result:accepted6 time:36 Ms7 memory:804 KB8 ****************************************************************/9  Ten#include <cstdio> One   A using namespacestd; -   - intans, sum; the   - intMain () { -     CharCH =GetChar (); -      while(ch = ='('|| ch = =')') { +         if(ch = ='(') ++sum; -         Else--sum; +         if(Sum <0) ++ans, sum + =2; ACH =GetChar (); at     } -Ans + = sum >>1; -printf"%d\n", ans); -     return 0; -}
View Code

BZOJ3016 [Usaco2012 Nov]clumsy cows

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.