题意:一个'('  ,  ')'  ,  '#'组成的串,可将'#'换成至少一个')'。问一个换法能使串匹配。

至少换成一个,那么就先都换成一个,记结果为str。最后一个')'的后面没有未匹配的'('时可行。否则输出-1。因为后面不可能再添加')'了。如果str会因为')'匹配不到'('则无解。否则有解,将str中'('的数量-')'的数量加到最后一个串中。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-; int work(string &str)
{
int res=;
stack<char> stk;
for(int i=;i<str.size();++i)
{
if(str[i]=='(')
{
stk.push(str[i]);
}
else
{
if(stk.empty())
{
return INF;
}
else
{
stk.pop();
}
}
}
return stk.size();
} bool work2(string &str)
{
stack<char> stk;
for(int i=;i<str.size();++i)
{
if(str[i]=='(')
{
stk.push('(');
}
else
{
if(!stk.empty())
{
stk.pop();
}
}
}
return stk.empty();
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
string str;
cin>>str;
int resnum=count(str.begin(),str.end(),'#');
int last=str.find_last_of('#');
string sub=str.substr(last+,str.size());
//cout<<sub<<endl;
for(int i=;i<str.size();++i)
{
if(str[i]=='#')str[i]=')';
}
int res=work(str);
// int cnt1=count(str.begin()+last+1,str.end(),'(');
// int cnt2=count(str.begin()+last+1,str.end(),')');
// if(cnt1>cnt2)res=INF;
//cout<<resnum<<endl;
if(!work2(sub))res=INF;
if(res!=INF)
for(int i=;i<resnum;++i)
{
if(i!=resnum-)cout<<<<endl;
else cout<<+res<<endl;
}
else cout<<-<<endl;
return ;
}

codeforces 494a//Treasure// Codeforces Round #282(Div. 1)的更多相关文章

  1. Codeforces Round #282 (Div. 1) A. Treasure 水题

    A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...

  2. Codeforces Round #282 Div.1 B Obsessive String --DP

    题意: 给两个串S,T,问能找出多少的S的(a1,b1)(a2,b2)..(ak,bk),使Sa1---Sb1,...Sak---Sbk都包含子串T,其中k>=1,且(a1,b1)...(ak, ...

  3. 数学 Codeforces Round #282 (Div. 2) B. Modular Equations

    题目传送门 题意:a % x == b,求符合条件的x有几个 数学:等式转换为:a == nx + b,那么设k = nx = a - b,易得k的约数(>b)的都符合条件,比如a=25 b=1 ...

  4. Codeforces Round #282 (Div. 1)B. Obsessive String KMP+DP

    B. Obsessive String   Hamed has recently found a string t and suddenly became quite fond of it. He s ...

  5. Codeforces Round #282 (Div. 2) A

    解题思路:用数组将每一个显示数字可能表示的数字种数存储起来即可 反思:第一次做的时候没有做出来是因为题意理解错误,第二次WA是因为情况没有考虑完全,1对应有7个数字,5对应有4个数字       A. ...

  6. Codeforces Round #577 (Div. 2) D. Treasure Hunting

    Codeforces Round #577 (Div. 2)  D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. Sa身份登陆SQL SERVER失败的解决方案

    经常使用windows身份登陆,久而久之,基本不动怎么用SQL SERVER身份验证登陆,所以趁着有空,就解决一下一些问题~~ 解决方案:  第一步:打开SSMS,先使用windows身份登陆,右击服 ...

  2. Hive 大数据倾斜总结

    在做Shuffle阶段的优化过程中,遇 到了数据倾斜的问题,造成了对一些情况下优化效果不明显.主要是因为在Job完成后的所得到的Counters是整个Job的总和,优化是基于这些 Counters得出 ...

  3. centos infiniband网卡安装配置

    硬件:Mellanox InfiniBand,主要包括 HCA(主机通道适配器)和交换机两部分 软件:CentOS 6.4 MLNX_OFED_LINUX-2.1-1.0.0-rhel6.4-x86_ ...

  4. python之路----面向对象的封装特性

    封装 [封装] 隐藏对象的属性和实现细节,仅对外提供公共访问方式. 广义上面向对象的封装 :代码的保护,面向对象的思想本身就是一种只让自己的对象能调用自己类中的方法 狭义上的封装 —— 面向对象的三大 ...

  5. STM8S003F3通过PWM波实现三基色呼吸灯(转)

    源: STM8S003F3通过PWM波实现三基色呼吸灯

  6. hash-补做

    题目 利用除留余数法为下列关键字集合的存储设计hash函数,并画出分别用开放寻址法和拉链法解决冲突得到的空间存储状态(散列因子取0.75) 关键字集合:85,75,57,60,65,(你的8位学号相加 ...

  7. linux性能分析工具之火焰图

    一.环境 1.1 jello@jello:~$ uname -a Linux jello 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UT ...

  8. P4013 数字梯形问题 网络流二十四题

    P4013 数字梯形问题 题目描述 给定一个由 nn 行数字组成的数字梯形如下图所示. 梯形的第一行有 m 个数字.从梯形的顶部的 m 个数字开始,在每个数字处可以沿左下或右下方向移动,形成一条从梯形 ...

  9. 论文笔记—Flattened convolution neural networks for feedforward acceleration

    1. 论文思想 一维滤过器.将三维卷积分解成三个一维卷积.convolution across channels(lateral), vertical and horizontal direction ...

  10. java的基本数据类型默认值

    这里就举int类型 默认值在类实例化,也就是对象中才有默认值0,或者是静态变量. 1.先看局部变量使用(不行,报错) 2.静态变量 3.类非静态属性