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

至少换成一个,那么就先都换成一个,记结果为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. 奋斗史-IT女生是怎样炼成的

    IT女生的奋斗史 终于来到了毕业季,感觉有点伤感! 记得11年来到大学的时候,还是那么懵懂,什么都不懂,几乎连电脑的基本操作都不会!自己小时候虽然家里穷,但是从小就觉得“软件”是个很神奇的东西,很了不 ...

  2. 隐马尔科夫模型(HMM)学习笔记二

    这里接着学习笔记一中的问题2,说实话问题2中的Baum-Welch算法编程时矩阵转换有点烧脑,开始编写一直不对(编程还不熟练hh),后面在纸上仔细推了一遍,由特例慢慢改写才运行成功,所以代码里面好多处 ...

  3. 如何在Apache中运行Python脚本

    第一步:进入C:\Apache24\cgi-bin: 第二步:在cgi-bin目录下新建一个hello.py文件: 第三步: #!python #coding:utf-8 print("co ...

  4. 推荐:Java性能优化系列集锦

    Java性能问题一直困扰着广大程序员,由于平台复杂性,要定位问题,找出其根源确实很难.随着10多年Java平台的改进以及新出现的多核多处理器,Java软件的性能和扩展性已经今非昔比了.现代JVM持续演 ...

  5. STM32f103C8T6 Bootloader设计(转)

    源:STM32f103C8T6 Bootloader设计 STM32F103c8t6通过串口实现IAP在线升级固件

  6. 基于qml创建最简单的图像处理程序(2)-使用c++&qml进行图像处理

     <基于qml创建最简单的图像处理程序>系列课程及配套代码基于qml创建最简单的图像处理程序(1)-基于qml创建界面http://www.cnblogs.com/jsxyhelu/p/8 ...

  7. node包管理工具--nvm(windows)

    windows 安装nvw-windows 使用nvm工具: windows使用nvm-noinstall.zip安装 nvm-noinstall.zip 这个是绿色免安装版本,但是使用之前需要配置 ...

  8. 我们能从 jQuery 的一个正则表达式中学到什么?

    注意,该篇文章当前为粗糙的 v0.9 版本,会在稍后润色更新. 让我们来看一道思考题,根据 rejectExp,分析其正则执行过程中如何进行过滤?包含哪些执行步骤? rejectExp 变量的值如下: ...

  9. 简单Shell案例

    使用shell命令进行左对齐或者右对齐 [root@bj-aws-yace-tbj mnt]# cat test.sh #! /bin/bash file=./test.txt echo -e &qu ...

  10. 02_Python简单爬虫(熊猫直播LOL的up主,谁最强!)

    声明: 本文仅用于Python练手,并无任何恶意攻击行为! # 导入request模块 from urllib import request # 导入re模块 import re class Spid ...