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 ...
随机推荐
- Android &Swift iOS开发:语言与框架对比
转载自:http://www.infoq.com/cn/articles/from-android-to-swift-ios?utm_campaign=rightbar_v2&utm_sour ...
- debug运行可以,release运行报错的原因及修改方法
通常我们开发的程序有2种模式:Debug模式和Release模式在Debug模式下,编译器会记录很多调试信息,也可以加入很多测试代码,方便我们程序员测试,以及出现bug时的分析解决Release模式下 ...
- Windows编译安装mod_wsgi,配合使用Django+Apahce
编译环境: 均是32位版本 Microsoft Visual Studio 10.0 Microsoft SDKs v7.1 Apache2.4 Python3.4 mod_wsgi-4.5.0 要求 ...
- Node.js学习 - File Operation
同步异步 文件系统(fs 模块)模块中的方法均有异步和同步版本,例如读取文件内容的函数有异步的 fs.readFile() 和同步的 fs.readFileSync(). 异步的方法函数最后一个参数为 ...
- h5移动端设计页面
@京东设计中心 :去年JDC出了不少优秀的武媚娘…不,H5呢,大家都很拼,同时当然也积累了一些经验和教训,今天结合咱们的实战案例,从字体,排版,动效,音效,适配性,想法这几个方面好好聊一聊关于H5的设 ...
- C#调用C++动态库时类型转换
因为本人主要从事c#开发,但是在工作中经常需要用到c++编写的DLL,因此需要知道c++中的类型与c#中的类型是如何转换的.搜集整理如下. //C++中的DLL函数原型为 //extern &qu ...
- 面向对象重写(override)与重载(overload)区别
一.重写(override) override是重写(覆盖)了一个方法,以实现不同的功能.一般是用于子类在继承父类时,重写(重新实现)父类中的方法. 重写(覆盖)的规则: 1.重写方法的参数列表必须完 ...
- css叠加原则,就近原则
<html><head lang="en"> <meta charset="UTF-8"> <title>< ...
- CentOS 6.5配置mysql
启动mysql service mysqld start 给root账号设置密码 mysqladmin -u root password '
- STL入门2
1:给出n个字符串,输出每个字符串是第几个出现的字符串?多组数据 2:对每组数据,第一行输入n表示接下来有n个字符串 1 <= n <= 100000接下来的n行,每行输入一个非空的且长度 ...