3016: [Usaco2012 Nov]Clumsy Cows

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 91  Solved: 69
[Submit][Status][Discuss]

Description

Bessie the cow is trying to type a balanced string of parentheses into her new laptop, but she is sufficiently clumsy (due to her large hooves) that she keeps mis-typing characters. Please help her by computing the minimum number of characters in the string that one must reverse (e.g., changing a left parenthesis to a right parenthesis, or vice versa) so that the string would become balanced. There are several ways to define what it means for a string of parentheses to be "balanced". Perhaps the simplest definition is that there must be the same total number of ('s and )'s, and for any prefix of the string, there must be at least as many ('s as )'s. For example, the following strings are all balanced:
()
(())
()(()())
while these are not:
)(
())(
((())))
 
问题描述
给定长度为n的一个括号序列,每次修改可以修改一个位置的括号,若这个括号为’(‘,则修改为’)’,若这个括号为’)’,则修改为’(‘,问最少修改多少个使得原括号序列合法。
其中:
①     ()是合法的;
②     若A是合法的,则(A)是合法的;
③     若AB都是合法的,则AB是合法的。
 

Input

       一个长度为n个括号序列。
 

Output

 
       最少的修改次数。
 

Sample Input

())(

Sample Output

2

样例说明
修改为()(),其中红色部分表示修改的括号。

数据范围
100%的数据满足:1 <= n <= 100,000。

HINT

 

Source

Silver

题解:一个很神奇的模拟,感觉自己水水哒

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var ch:char;s,ans:longint;
begin
while not(eoln) do
begin
read(ch);
if ch='(' then inc(s) else
begin
dec(s);
if s< then
begin
inc(s,);
inc(ans);
end;
end;
end;
ans:=ans+s div ;
writeln(ans);
end.

3016: [Usaco2012 Nov]Clumsy Cows的更多相关文章

  1. 【BZOJ】3016: [Usaco2012 Nov]Clumsy Cows(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3016 之前yy了一个贪心,,,但是错了,,就是枚举前后对应的字符(前面第i个和后面第i个)然后相同答 ...

  2. BZOJ 3016 [Usaco2012 Nov]Clumsy Cows:贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3016 题意: 给你一个括号序列,问你至少修改多少个括号,才能使这个括号序列合法. 题解: ...

  3. BZOJ3016: [Usaco2012 Nov]Clumsy Cows

    3016: [Usaco2012 Nov]Clumsy Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 52[Submi ...

  4. USACO Clumsy Cows

    洛谷 P3056 [USACO12NOV]笨牛Clumsy Cows 洛谷传送门 JDOJ 2323: USACO 2012 Nov Silver 1.Clumsy Cows JDOJ传送门 Desc ...

  5. BZOJ3314: [Usaco2013 Nov]Crowded Cows

    3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 86  Solved: 61[Subm ...

  6. BZOJ 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛( dp )

    树形dp..水 ------------------------------------------------------------------------ #include<cstdio& ...

  7. BZOJ 3314: [Usaco2013 Nov]Crowded Cows( 单调队列 )

    从左到右扫一遍, 维护一个单调不递减队列. 然后再从右往左重复一遍然后就可以统计答案了. ------------------------------------------------------- ...

  8. 3314: [Usaco2013 Nov]Crowded Cows

    3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 111  Solved: 79[Sub ...

  9. 3018: [Usaco2012 Nov]Distant Pastures

    3018: [Usaco2012 Nov]Distant Pastures Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 43  Solved: 20[ ...

随机推荐

  1. Pomelo术语解释

    gate服务器 一个应用的gate服务器,一般不参与rpc调用,也就是说其配置项里可以没有port字段,仅仅有clientPort字段,它的作用是做前端的负载均衡.客户端往往首先向gate服务器发出请 ...

  2. 巧用css text-indent减小中文标点符号的占位大小

    由于设计需要,我们的页面中经常会有如下效果: 可是我们实现出来的效果确实这样的: 看起来两行文本没有对齐嘛,仔细检查后原来是[字符的原因,因为是中文标点符号占半个字的位置.不信?选中下汉字标点符号看一 ...

  3. 笔记:Ubuntu 上的Testlink 部署

    1.安装apache2 sudo apt-get install apache2 2. sudo /etc/init.d/apache2 restart 测试: Http:\localhost or ...

  4. 我的2016年终总结(PF项目框架设计心得分享 2.0rc)

    在无数的日夜里,熬出了多少的黑眼圈,致勤勤恳恳工作的各位朋友与自己.每到了年末的时候总想写的什么,主要是为了回顾以往一年里到底做了什么,这便是年终总结的主要意义.在此我将要总结的是和我在技术层面上成长 ...

  5. (四)Hololens Unity 开发之 凝视系统

    学习源于官方文档 Gaze in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 HoloLens 有三大输入系统,凝视点.手势和声音 ~ 本文主要记录凝视 ...

  6. (一)Lua脚本语言入门

    今天开始自己的Lua语言学习,Lua脚本语言,是介于应用程序和开发其应用程序的底层编程语言之间,,它很方便调用其它语言,它只是在载入时对其进行编译,而不像我们写的单片机程序是预编译的,先编译好然后写入 ...

  7. python 基础学习小记

    Python应该是写起来最舒服的动态语言了,一下是一些读书笔记,本文中安装的是3.0,有几点需要注意: print "xxx" 要换成 print("xxx") ...

  8. HTTP严格安全传输(HTTP Strict Transport Security, HSTS)chromuim实现源码分析(一)

    // HTTP strict transport security (HSTS) is defined in// http://tools.ietf.org/html/ietf-websec-stri ...

  9. HUST 1541 Student’s question

    1541 - Student’s question 时间限制:1秒 内存限制:128兆 696 次提交 134 次通过 题目描述 YYis a student. He is tired of calc ...

  10. Ninject之旅之十二:Ninject在Windows Form程序上的应用(附程序下载)

    摘要: 下面的几篇文章介绍如何使用Ninject创建不同类型的应用系统.包括: Windows Form应用系统 ASP.NET MVC应用系统 ASP.NET Web Form应用系统 尽管对于不同 ...