首先进行一次括号匹配,把正确匹配的全部删去。

删去之后剩下的状态肯定是 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的更多相关文章

  1. POJ 3991 括号匹配问题(贪心)

    I’m out of stories. For years I’ve been writing stories, some rather silly, just to make simple prob ...

  2. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  3. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  4. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  5. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  6. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  7. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  8. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  9. 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 ...

随机推荐

  1. strncasecmp与strcasecmp用法

    strcasecmp strcasecmp(忽略大小写比较字符串) 相关函数 bcmp,memcmp,strcmp,strcoll,strncmp 表头文件 #include<string.h& ...

  2. 在WIN7/8下把XP装入VHD (上)

    系统平台:win8.1 操作目的:工作中需要使用一个只能在winxp下运行的软件,但我平时都用win8.1,也不想弄个麻烦的双系统.在无忧论坛研究了两天后找到个比较好的办法,在VHD里装个window ...

  3. hdu 2544 最短路 (spfa)

    最短路 Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  4. 常用的JS页面跳转代码调用大全

    一.常规的JS页面跳转代码 1.在原来的窗体中直接跳转用 <script type="text/javascript"> window.location.href=&q ...

  5. VBS脚本和HTML DOM自动操作网页

    VBS脚本和HTML DOM自动操作网页 2016-06-16 10:24 1068人阅读 评论(0) 收藏 举报  分类: Windows(42)  版权声明:本文为博主原创文章,未经博主允许不得转 ...

  6. 利用未文档化API:RtlAdjustPrivilege 提权实现自动关机

    这里主要是利用NTDLL.dll中未文档化的API: RtlAdjustPrivilege 来实现提权.自动关机的功能. RtlAdjustPrivilege定义如下: NTSTATUS RtlAdj ...

  7. Selenium2+python自动化28-table定位

    前言 在web页面中经常会遇到table表格,特别是后台操作页面比较常见.本篇详细讲解table表格如何定位. 一.认识table 1.首先看下table长什么样,如下图,这种网状表格的都是table ...

  8. WordPress安装到zen-cart产品页中

    把WordPress安装到zen-cart一个子目录里吧,设置好固定连接等这个文件/includes/templates/template_default/templates/tpl_product_ ...

  9. hdu_5213_Lucky(莫队算法+容斥定理)

    题目连接:hdu_5213_Lucky 题意:给你n个数,一个K,m个询问,每个询问有l1,r1,l2,r2两个区间,让你选取两个数x,y,x,y的位置为xi,yi,满足l1<=xi<=r ...

  10. 【java链表 】java 头插法建单链表

    好久前练习用的,现在看难度不大. package project; class Node { private int id; //私有就是只能本类对象及方法访问. private String nam ...