首页 > 其他分享 >P3056 [USACO12NOV] Clumsy Cows S

P3056 [USACO12NOV] Clumsy Cows S

时间:2024-06-22 11:27:39浏览次数:11  
标签:parentheses string Clumsy P3056 样例 number balanced Cows must

[USACO12NOV] Clumsy Cows S

题目描述

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:

)(
())(
((())))

给出一个偶数长度的括号序列,问最少修改多少个括号可以使其平衡。

输入格式

* Line 1: A string of parentheses of even length at most 100,000 characters.

输出格式

* Line 1: A single integer giving the minimum number of parentheses that must be toggled to convert the string into a balanced string.

样例 #1

样例输入 #1

())(

样例输出 #1

2

提示

The last

标签:parentheses,string,Clumsy,P3056,样例,number,balanced,Cows,must
From: https://blog.csdn.net/m0_46192147/article/details/139867904

相关文章

  • 洛谷 P1204 [USACO1.2] 挤牛奶Milking Cows
    题意:给定n个区间,左端点和右端点表示工作开始时间和结束时间。求最长一直有人在工作的时间和无人工作的时间。思路:想到了并查集,还有差分树状数组,最后选择差分数组。左端点加,右端点减,然后一次遍历即可。总结:习惯性的在右端点+1的位置减少了1,但是不适用于这个题目的逻辑。因为在右......
  • P3052 [USACO12MAR] Cows in a Skyscraper G
    原题链接题解模拟,遍历n个物品,一开始一个箱子不给,遍历到某个物品时,先把所有已经给了的箱子放进去试试,再创一个新箱子放进去试试code#include<bits/stdc++.h>usingnamespacestd;intn,w;intcnt,ans;intchongdie=0;intbox[20],c[20];voidmoni(intnow,intcnt)//now......
  • P2742 [USACO5.1] 圈奶牛Fencing the Cows /【模板】二维凸包
    原题链接题解这么优质的文章我写什么题解好难解释必然性感觉像模拟??code#include<bits/stdc++.h>usingnamespacestd;intq[100005]={0};structnode{doublex,y;}a[100005];doubledis(intb,intc){nodei=a[b],j=a[c];returnsqrt((i.x-j.x)*(i.x-......
  • P3047 [USACO12FEB] Nearby Cows G
    原题链接题解核心技巧:两次搜索第一次搜索:搜索出\(f[now][i]\)以\(now\)为根节点的子树且距离根节点恰好为\(i\)的节点的个数搜索完了之后,把范围\(k\)以内的累加第二次搜索:由于整棵树的根节点的\(f\)等于整棵树里距离不大于\(k\)的节点个数,即已经符合题目要求......
  • 弱网罗测试工具clumsy
    clumsy能在Windows平台下人工造成不稳定的网络状况,方便你调试应用程序在极端网络状况下的表现。 简介利用封装WinodwsFilteringPlatform的WinDivert库,clumsy能实时的将系统接收和发出的网络数据包拦截下来,人工的造成延迟,掉包和篡改操作后再进行发送。无论你是要重......
  • 弱网模拟工具Clumsy
    Clumsy是基于C语言开发的一款开源网络模拟工具。它能在Windows平台下人工造成不稳定的网络状态,应用它可以方便调试应用程序在极端网络状态下的表现。一、下载安装软件下载地址:http://jagt.github.io/clumsy/cn/download首先请根据你系统的版本(32位或64位)下载clumsy最新版本......
  • P7154 Sleeping Cows 题解
    传送门题意:给定两个数组\(a_i,b_i\),若\(a_i\leb_j\),则他俩可配对。求极大匹配的方案数。(极大不是最大,最大一定是极大)先考虑最大匹配方案数怎么求。把\(a\)和\(b\)从小到大排序。则每个\(a_i\)能匹配的\(b\)都是一段后缀,且随着\(i\)增大,这个后缀越来越小。于是从......
  • P1204 [USACO1.2] 挤牛奶Milking Cows
    原题链接题解细节颇多看代码code#include<bits/stdc++.h>usingnamespacestd;structunit{ints,e;}milk[5005];boolcmp(unita,unitb){returna.s<b.s;}intmain(){intn;cin>>n;for(inti=1;i<=n;i++)cin>>milk[i].s......
  • [USACO07DEC] Sightseeing Cows G
    [USACO07DEC]SightseeingCowsG题目描述FarmerJohnhasdecidedtorewardhiscowsfortheirhardworkbytakingthemonatourofthebigcity!Thecowsmustdecidehowbesttospendtheirfreetime.Fortunately,theyhaveadetailedcitymapshowingthe$L......
  • P9194 [USACO23OPEN] Triples of Cows P 题解
    Description给定一棵初始有\(n\)个点的树。在第\(i\)天,这棵树的第\(i\)个点会被删除,所有与点\(i\)直接相连的点之间都会两两连上一条边。你需要在每次删点发生前,求出满足\((a,b)\)之间有边,\((b,c)\)之间有边且\(a\not=c\)的有序三元组\((a,b,c)\)对数。\(n\leq2......