Description [Brian Dean, 2012] Farmer John's cows are all of a very peculiar breed known for its distinctive appearance -- each cow is marked with a giant spot on its hide in the shape of a parenthesis (depending on the direction the cow is facing, t…
题面 [USACO12NOV]同时平衡线Concurrently Balanced Strings 题解 考虑DP. \(f[i]\)表示以\(i\)为左端点的合法区间个数.令\(pos[i]\)表示以\(i\)为左端点,最靠左的合法右端点. 那么有如下转移: \(f[i] = f[pos[i] + 1] + 1\). 1表示[i, pos[i]]这段合法区间,\(f[pos[i] + 1]\)表示在这段合法区间的基础上,还可以在后面拼接更多合法区间. 那么我们的目的就是求\(pos[i]\).…
3016: [Usaco2012 Nov]Clumsy Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 71  Solved: 52[Submit][Status] Description Bessie the cow is trying to type a balanced string of parentheses into her new laptop, but she is sufficiently clumsy (due to h…
3016: [Usaco2012 Nov]Clumsy Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 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…
3018: [Usaco2012 Nov]Distant Pastures Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 43  Solved: 20[Submit][Status][Discuss] Description Farmer John's farm is made up of an N x N grid of pastures, where each pasture contains one of two different type…
Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced string s split it in the maximum amount of balanced strings. Return the maximum amount of splitted balanced strings. Example 1: Input: s = "RLRRLLRLRL"…
题目如下: Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced string s split it in the maximum amount of balanced strings. Return the maximum amount of splitted balanced strings. Example 1: Input: s = "RLRRLLRLR…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计 日期 题目地址:https://leetcode.com/problems/split-a-string-in-balanced-strings/ 题目描述 Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced…
http://www.lydsy.com/JudgeOnline/problem.php?id=3016 之前yy了一个贪心,,,但是错了,,就是枚举前后对应的字符(前面第i个和后面第i个)然后相同答案就+1,否则不操作.. QAQ 然后看了题解...神.. 首先序列肯定是偶数个,然后..一定有n/2个‘(’,和n/2个‘)’ 那么左边的一定都是‘(’,对于每一个‘(’,右边的一定有一个‘)’,所以我们想到差分,当右边多了‘)’,那么就要累计答案+1,维护一个sum,如果是‘(’就+1,‘)’就…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3016 题意: 给你一个括号序列,问你至少修改多少个括号,才能使这个括号序列合法. 题解: 贪心. cnt表示当前已经攒了多少个左括号. 从左往右枚举每一个括号: (1)如果为左括号,则cnt++. (2)如果为右括号,且cnt > 0,则cnt--.表示消去了一个左括号. (3)如果为右括号,且cnt <= 0,则cnt++,ans++.因为此时一定要改. 最后ans还要加上cnt/2…