topcoder SRM 628 DIV2 BracketExpressions
先用dfs搜索所有的情况,然后判断每种情况是不是括号匹配
#include <vector>
#include <string>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <queue> using namespace std; class BracketExpressions
{
public:
string src,dst;
const string bracket="()[]{}"; bool check(string& str){
stack<char> st;
for(int i = ; i < str.length(); ++ i){
if(st.empty()) st.push(str[i]);
else{
char ch = st.top();
if((str[i]==']'&& ch=='[')||(str[i] == '}' && ch=='{') || (str[i]==')'&& ch=='(')) st.top();
else st.push(str[i]);
}
}
cout<<st.size()<<endl;
return st.empty()?true:false;
} bool dfs(int cur){
if(cur==src.length()) return check(dst);
if(src[cur]=='X'){
bool flag = false;
for(int i = ; i < bracket.length();++i){
dst[cur]=bracket[i];
flag|=dfs(cur+);
}
return flag;
}else return dfs(cur+);
} string ifPossible(string expression)
{
src=dst=expression;
return dfs()?"possible":"impossible";
} }; // Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor // Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor
topcoder SRM 628 DIV2 BracketExpressions的更多相关文章
- topcoder srm 628 div2 250 500
做了一道题,对了,但是还是掉分了. 第二道题也做了,但是没有交上,不知道对错. 后来交上以后发现少判断了一个条件,改过之后就对了. 第一道题爆搜的,有点麻烦了,其实几行代码就行. 250贴代码: #i ...
- topcoder SRM 628 DIV2 BishopMove
题目比较简单. 注意看测试用例2,给的提示 Please note that this is the largest possible return value: whenever there is ...
- Topcoder Srm 673 Div2 1000 BearPermutations2
\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...
- Topcoder Srm 671 Div2 1000 BearDestroysDiv2
\(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...
- 求拓扑排序的数量,例题 topcoder srm 654 div2 500
周赛时遇到的一道比较有意思的题目: Problem Statement There are N rooms in Maki's new house. The rooms are number ...
- Topcoder srm 632 div2
脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...
- Topcoder SRM 628 DIV 2
被自己蠢哭了.... 250-point problem 国际象棋棋盘上给出两个坐标,问象从一个走到还有一个最少要几步. 黑格象仅仅能走黑格,白格象仅仅能走白格,仅仅要推断两个坐标的颜色是否同样就能推 ...
- SRM 628 DIV2
250 想想就发现规律了. 500 暴力,括号匹配. 1000 给一个f数组,如果i存在,那么f[i]也得存在,问这样的集合有多少种. 先拓扑一下,dp[i] = mul(dp[son]+1)最后 ...
- Topcoder SRM 683 Div2 B
贪心的题,从左向右推过去即可 #include <vector> #include <list> #include <map> #include <set&g ...
随机推荐
- Java学习——连接数据库
1.去官网下载对应版本的Ojdbc.jar(oracle).sqljdbc.jar(sqlserver). 2.放置到项目lib文件夹下 3.项目右键->Build Path->confi ...
- Java的国际化(i18n)
http://blog.csdn.net/csuliky/article/details/4225800 1. Java国际化简介 Java既然作为一个跨平台的语言就必然要在各种不同的语言环境中使用, ...
- iOS10 权限崩溃问题
iOS10 权限崩溃问题 原文: http://blog.csdn.net/runleelrg/article/details/51673025 今天 手机升级了 iOS10 Beta,然后用正在开发 ...
- How the problem solved about " Dealing with non-fast-forward errors"
Recently ,I got confused When I use git to push one of my project. The problem is below: And I Foun ...
- PYTHON 随机验证码生成
# 生成一个六位随机验证码 import random # random 生成随机数 temp = '' for i in range(6): num = random.randrange(0,6) ...
- visual studio 2013 中配置OpenCV2.4.13 姿势
首先在path中添加 “C:\OpenCV\opencv\build\x64\vc12\bin” (地址随实际变化) 注:添加的都是*86不使用*64 在visualstudio 2013中配置 ...
- html5 canvas-变幻函数
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 设计模式--组合模式Composite(结构型)
一.概念 组合模式允许你将对象组合成树形结构来表现"整体/部分"层次结构.组合能让客户以一致的方式处理个别对象以及对象组合. 二.UML图 1.Component(对象接口),定义 ...
- iOS self
如果self在对象方法中 那么self就代表调用当前对象方法的那个对象 如果self在类方法中 那么self就代表调用当前类方法的那个类 总结:self的使用只需关注self在哪个方法中 如果在类方法 ...
- 一键启动NameNode和DataNode--shell脚本
使用shell脚本,一键启动hadoop中的NameNode和DataNode.分为普通版和装逼版.装逼版较普通版多了很多判断和信息提示,当然主要还是为了我联系shell脚本而写的. 如果想实现复用, ...