UVA 12902 Reverse Polish Notation
//跟wyr学的
//其实是贪心
//题解稍后补上
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string>
#define LL long long const int MAXN=;
const int MAXM=;
const int INF=; using namespace std; int T;
char s[]; int solve(){
int len=strlen(s);
int MIN=INF;
int now=;
int flag=;
for (int i=;i<len;i++){
if (s[i]=='a')
now++;
else
now--;
if (now==MIN) flag=;
if (now<MIN){
MIN=now;
flag=;
}
}
if (MIN>=) return now-;
if (MIN==now) return +abs(now);
return +now-MIN*-flag;
} int main(){
scanf("%d",&T);
for (int cas=;cas<=T;cas++){
scanf("%s",s);
int ans=solve();
if (s[]=='+' && s[]=='a' && s[]=='a'){
s[]='a';
s[]='a';
s[]='+';
ans=min(ans,solve()+);
}
printf("Case %d: %d\n",cas,ans);
}
return ;
}
/*
4
a
a+a
+aa
aa++++a
*/
UVA 12902 Reverse Polish Notation的更多相关文章
- [LeetCode] Evaluate Reverse Polish Notation 计算逆波兰表达式
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- 【leetcode】Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation 题目描述: Evaluate the value of an arithmetic expression in Reverse Pol ...
- leetcode150 Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- 【leetcode】Evaluate Reverse Polish Notation(middle)
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- Leetcode Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- [LintCode] Evaluate Reverse Polish Notation 计算逆波兰表达式
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- 11. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- LeetCode OJ 150. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- Java for LeetCode 150 Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
随机推荐
- live555学习之RTSP连接建立以及请求消息处理过程
1,RTSP连接的建立过程 RTSPServer类用于构建一个RTSP服务器,该类同时在其内部定义了一个RTSPClientSession类,用于处理单独的客户会话. 首先创建RTSP服务 ...
- EF中读取随机数据的问题
_list.Where(a=>a.级别=="1").OrderBy(a => Guid.NewGuid()).Take(10);
- LeeCode-Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- POJ1988 并查集的使用
Cube Stacking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 21157 Accepted: 7395 Ca ...
- zoj 3471 Most Powerful(状态压缩dp)
Recently, researchers on Mars have discovered N powerful atoms. All of them are different. These ato ...
- One Way Roads(搜索)
One Way Roads Time Limit:500MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- VF(动态规划)
VF 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Vasya is the beginning mathematician. He decided to make a ...
- Eddy's picture(prime+克鲁斯卡尔)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- 【十】注入框架RoboGuice使用:(Your First Testcase)
上一篇我们简单的介绍了一下RoboGuice的使用([九]注入框架RoboGuice使用:(Your First Injected Service and BroadcastReceiver)),今天 ...
- Android多媒体开发-- android中OpenMax的实现整体框架
1.android中用openmax来干啥? android中的AwesomePlayer就 是用openmax来做(code)编解码,其实在openmax接口设计中,他不光能用来当编解码.通过他的组 ...