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 ...
随机推荐
- Html to Pdf 的另类解决方案
Background 项目里要求将一个HTML页面(支付结果)生成pdf文档.页面有图片,有表格,貌似开源的iTextSharp应付不了. 在一番搜索之后,找到了wkhtmltopdf,一个命令行的开 ...
- 转载请注明出处: https://github.com/qiu-deqing/FE-interview
转载请注明出处: https://github.com/qiu-deqing/FE-interview Table of Contents generated with DocToc FE-inter ...
- [BZOJ3223]Tyvj 1729 文艺平衡树
[BZOJ3223]Tyvj 1729 文艺平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区 ...
- 共享MFC dULL
>------ 已启动生成: 项目: OSGtest, 配置: Debug Win32 ------1>正在编译...1>AddScene.cpp1>main.cpp1> ...
- Android带图片的Toast(自定义Toast)
使用Android默认的Toast Toast简介: Toast是一个简单的消息显示框,能够短暂的出现在屏幕的某个位置,显示提示消息. 默认的位置是屏幕的下方正中,一般Toast的使用如下: Toas ...
- Appium for iOS setup
windows下appium设置 之前研究了一段时间的appium for native app 相应的总结如下: ...
- js中子页面父页面方法 变量相互调用
(1)子页面调用父页面的方法或者变量: window.parent.方法()或者变量名window.parent相当于定位到父页面 之后的操作和在父页面中写代码一样写 window.parent.a ...
- 【JavaScript】--重点解析之跨域请求
JSON JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. JSON是用字符串来表示Javascript对象,例如可以在django中发送一个JSON格式 ...
- Java_太阳系_行星模型_小游戏练习_详细注释
//实现MyFrame--实现绘制窗口,和实现重写 重画窗口线程类 package cn.xiaocangtian.Test; import java.awt.Frame; import java.a ...
- Redis之清除所有缓存
方法: /// <summary> /// 清除redis所有缓存 /// </summary> /// <param name="redisUrl" ...