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

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…
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…
洛谷 P3056 [USACO12NOV]笨牛Clumsy Cows 洛谷传送门 JDOJ 2323: USACO 2012 Nov Silver 1.Clumsy Cows JDOJ传送门 Description Problem 1: Clumsy Cows [Brian Dean, 2012] Bessie the cow is trying to type a balanced string of parentheses into her new laptop, but she is su…
3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 86  Solved: 61[Submit][Status] Description Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(i) and has…
树形dp..水 ------------------------------------------------------------------------ #include<cstdio> #include<algorithm> #include<cstring> #include<iostream>   #define rep( i , n ) for( int i = 0 ; i < n ; i++ ) #define clr( x , c…
从左到右扫一遍, 维护一个单调不递减队列. 然后再从右往左重复一遍然后就可以统计答案了. ---------------------------------------------------------------------------- #include<bits/stdc++.h>   #define rep(i, n) for(int i = 0; i < n; ++i) #define clr(x, c) memset(x, c, sizeof(x)) #define for…
3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 111  Solved: 79[Submit][Status][Discuss] Description Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(…
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…