codeforces 494a//Treasure// Codeforces Round #282(Div. 1)
题意:一个'(' , ')' , '#'组成的串,可将'#'换成至少一个')'。问一个换法能使串匹配。
至少换成一个,那么就先都换成一个,记结果为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)的更多相关文章
- Codeforces Round #282 (Div. 1) A. Treasure 水题
A. Treasure Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/494/problem/A ...
- 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, ...
- 数学 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 ...
- 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 ...
- Codeforces Round #282 (Div. 2) A
解题思路:用数组将每一个显示数字可能表示的数字种数存储起来即可 反思:第一次做的时候没有做出来是因为题意理解错误,第二次WA是因为情况没有考虑完全,1对应有7个数字,5对应有4个数字 A. ...
- Codeforces Round #577 (Div. 2) D. Treasure Hunting
Codeforces Round #577 (Div. 2) D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- pandas练习(三)------ 数据分组
探索酒类消费数据 相关数据见(github) 步骤1 - 导入pandas库 import pandas as pd 步骤2 - 数据集 path3 = "./data/drinks.csv ...
- Linux其他:环境变量配置
计算机==>右键==>属性==>高级系统设置==>环境变量==> 系统变量path后面+';python路径名
- Python中type的用法
目录 描述 语法 用法 type和isinstance Type和Object 描述 python的 type 函数有两个用法,当只有一个参数的时候,返回对象的类型.当有三个参数的时候返回一个类对象. ...
- 限制 input 输入框只能输入纯数字
oninput = "value=value.replace(/[^\d]/g,'')"
- 彻底明白Flink系统学习5:window、Linux本地安装Flink
http://www.aboutyun.com/thread-26393-1-1.html 问题导读 1.如何在window下安装Flink? 2.Flink本地安装启动命令与原先版本有什么区别? 3 ...
- 全面理解Java内存模型(转)
转自:http://blog.csdn.net/suifeng3051/article/details/52611310 Java内存模型即Java Memory Model,简称JMM.JMM定义了 ...
- UVA1714 Keyboarding(bfs)
UVA1714 Keyboarding bfs 坑点很多的一题(由于一本通的辣鸡翻译会错题意*n). 1.多组数据 2.如果某方向上没有不同字符光标不会动 我们每次预处理出每个点向四个方向下次到达的点 ...
- Linux下Tomcat同时部署两个工程然而只有一个能访问问题
Linux下Tomcat同时部署两个工程然而只有一个能访问问题 问题: Linux下单个部署到Tomcat下的时候都正常,两个一起部署,只有一个能访问: 解决方案: 由于采用#./shutdown.s ...
- exp9《网络对抗》web安全基础实践201453331魏澍琛
201453331魏澍琛web安全基础实践 一.实验过程 1.webgoat开启 2.Injection Flaws练习 Command Injection 原网页中没有注入的地方,那就用burpsu ...
- Android实践项目汇报(三)
Google天气客户端 本周学习计划 调试代码使之成功运行并实现天气预报功能. 实际完成情况 由于google取消api接口服务,天气源的传输.所以我换了一个使用 haoserver API接口的程序 ...