POJ 3991 Seinfeld
首先进行一次括号匹配,把正确匹配的全部删去。
删去之后剩下的状态肯定是 L个连续右括号+R个连续左括号。
如果L是偶数,答案是L/2+R/2;
否则答案是 (L-1)/2+(R-1)/2+2;
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<stack>
#include<algorithm>
using namespace std; char s[ + ];
char st[ + ];
int top; int main()
{
int T = ;
while (~scanf("%s", s))
{
int ans = ;
memset(st, , sizeof st);
top = -;
if (s[] == '-') break;
for (int i = ; s[i]; i++)
{
if (top == -) st[++top] = s[i];
else
{
if (st[top] == '{'&&s[i] == '}')
{
st[top] = ;
top--;
}
else st[++top] = s[i];
}
} int L = , R = ;
for (int i = ; st[i]; i++)
{
if (st[i] == '}') L++;
else R++;
}
if (L % == ) ans = L / + R / ;
else ans = (L - ) / + (R - ) / + ;
printf("%d. %d\n", T++, ans);
}
return ;
}
POJ 3991 Seinfeld的更多相关文章
- POJ 3991 括号匹配问题(贪心)
I’m out of stories. For years I’ve been writing stories, some rather silly, just to make simple prob ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
随机推荐
- JS限制 获取动太ID,播放视频
JS限制textarea字数 function textdown(e) {textevent = e ; ) { return; } ) { alert("大侠,我手机屏幕小,先输入这么多字 ...
- HDU 5323 DFS
DFS Time Limit : 5000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissio ...
- Json.net对数据的解析
在官网下载Json.net文件后,解压完将Net20下面的DLL复制到Assets目录下. using UnityEngine; using System.Collections; using New ...
- USB的八个问题和答案(转)
http://www.amobbs.com/thread-901041-1-1.html 问题一:USB的传输线结构是如何的呢? 答案一:一条USB的传输线分别由地线.电源线.D+.D-四条线构成,D ...
- 51nod 区间中第K大的数
区间中第K大的数 基准时间限制:1 秒 空间限制:131072 KB 一个长度为N的整数序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,第K大的数是多少. 例如: 1 7 6 ...
- HDU 1203 I NEED A OFFER! 01背包 概率运算预处理。
题目大意:中问题就不说了 ^—^~ 题目思路:从题目来看是很明显的01背包问题,被录取的概率记为v[],申请费用记为w[].但是我们可以预先做个处理,使问题解决起来更方便:v[]数组保留不被录取的概率 ...
- POJ 3660 Cow Contest 弗洛伊德
题意难懂是POJ的标配,这都TM赖本泽马. 题意:有N头牛进行了M场比赛,比赛双方是A - B 且总是A赢(前面的那个数赢),如果说A赢B,B赢C 则可以确定A赢C.问最终多少头牛的排名可以确定. 思 ...
- shell中break 与 continue
在学习中我看到不单单有break和continue的存在,还有break -n 和 continue -n 的存在 那么它们有什么区别呢. 这时可以写出测设代码: for i in a b c ...
- Winform带dataGridview的Combox控件
调用控件: public partial class Form1 : Form { public Form1() { InitializeComponent(); //---------------- ...
- WebDriver(Selenium2) 常见异常及处理方法
http://uniquepig.iteye.com/blog/1568197 Exception NoSuchElementException Solutions 1. Check the l ...