HDU 1082
http://acm.hdu.edu.cn/showproblem.php?pid=1082
这题开始想复杂了,error并不包括表达式本身不合法的情况
我的方法是遇到右括号就开始处理栈,如果开始最外层没有括号,就人为加上
数据应该是比较弱的,一通乱搞
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack> using namespace std ;
int n ; struct Mat
{
int op ;
int r,c ;
}M[] ;
Mat cc[] ;
char s[],ss[] ;
int main()
{
scanf("%d",&n) ;
for(int i= ;i<n ;i++)
{
char op[] ;
scanf("%s%d%d",op,&M[i].r,&M[i].c) ;
M[i].op=op[] ;
}
int tt=n ;
while(~scanf("%s",s))
{
n=tt ;
int len=strlen(s) ;
if(s[]!='(')
{
for(int i= ;i<=len ;i++)
ss[i]=s[i-] ;
ss[]='(' ;ss[len+]=')' ;
len+= ;
for(int i= ;i<len ;i++)
s[i]=ss[i] ;
}
int flag= ;
for(int i= ;i<len ;i++)
{
if(s[i]=='(' || s[i]==')')
{
flag= ;
break ;
}
}
int ans= ;
int ct= ;
stack <int> st ;
flag= ;
for(int i= ;i<len ;i++)
{
if(s[i]!=')')
{
st.push(s[i]) ;
}
else
{
int cnt= ;
while()
{
if(st.empty())break ;
if(st.top()=='(')
{
st.pop() ;
break ;
}
int temp=st.top() ;
st.pop() ;
for(int j= ;j<n ;j++)
{
if(M[j].op==temp)
{
cc[cnt++]=M[j] ;
break ;
}
}
}
for(int j=cnt- ;j>= ;j--)
{
if(cc[j+].c==cc[j].r)
{
ans+=(cc[j+].r*cc[j+].c*cc[j].c) ;
}
else
{
flag= ;
break ;
}
cc[j].r=cc[j+].r ;
}
if(!flag)break ;
cc[].op=ct++ ;
M[n++]=cc[] ;
st.push(cc[].op) ;
}
if(!flag)break ;
}
if(flag)printf("%d\n",ans) ;
else puts("error") ;
}
return ;
}
HDU 1082的更多相关文章
- hdu 1082, stack emulation, and how to remove redundancy 分类: hdoj 2015-07-16 02:24 86人阅读 评论(0) 收藏
use fgets, and remove the potential '\n' in the string's last postion. (main point) remove redundanc ...
- Uva442 hdu 1082 Matrix Chain Multiplication
要注意取出来的时候 先取出q的是后面那个矩阵 后取出p的是前面的矩阵 所以是判断 p.a == q.b #include <iostream> #include <stack> ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- [转] HDU 题目分类
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- hdu 分类
HDU分类 http://www.cnblogs.com/ACMan/archive/2012/05/26/2519550.html#2667329 努力A完.方便自己系统A题 不断更新中...... ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- jquery中ajax常用方法
index.html: <h3>$.get(url, [data], [callback], [type])<br/> $.post(url, [data], [callbac ...
- hadoop工作流引擎之azkaban [转]
介绍 Azkaban是twitter出的一个任务调度系统,操作比Oozie要简单很多而且非常直观,提供的功能比较简单.Azkaban以Flow为执行单元进行定时调度,Flow就是预定义好的由一个或多个 ...
- PHP多线程类
<?php /** * @title: PHP多线程类(Thread) * @version: 1.0 * @author: phper.org.cn < web@phper.org.cn ...
- IISExpress配置文件的一个坑
现象: 昨天在处理PBS系统问题的时候意外发现两个js错误(而同样的代码在同事机器上都没有问题),如下图. 图1 图2 图3 原因分析: 初步看起来是因为页面上没有id为'form1'的form和id ...
- 利用LM神经网络和决策树去分类
# -*- coding: utf-8 -*- import pandas as pd from scipy.interpolate import lagrange from matplotlib i ...
- 10款优秀Vim插件帮你打造完美IDE
导读 如果你稍微写过一点代码,就能知道“集成开发环境”(IDE)是多么的便利.不管是Java.C还是Python,当IDE会帮你检查语法.后台编译,或者自动导入你需要的库时,写代码就变得容易许多.另外 ...
- 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision
char *ptr; //此后省略部分代码 ) //出错地方 那句话的意思是从 void* 到 int 的转换丢失精度,相信看到解释有些人就明白了, 此问题只会出现在X64位的Linux上,因为在64 ...
- caches 文件夹删除
模拟器 可以 删除 真机不行
- C++-模板的声明和实现为何要放在头文件中
源: http://blog.csdn.net/lqk1985/archive/2008/10/24/3136364.aspx 如何组织编写模板程序 发表日期: 1/21/2003 12:28:58 ...
- PS通道抠图总结
看了那么多的通道抠图,总结几点就是 1.你要有很强的色彩意识,怎样调节对比色等才能增加主体和背景的色差 2.流水步骤 Ctrl+J复制背景图层 调整主体和背景的色差 进入通道面板,找到主体和背景对比最 ...