UVA 12902 Reverse Polish Notation
2024-08-26 12:07:55
//跟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
*/
最新文章
- springMVC初探--环境搭建和第一个HelloWorld简单项目
- android上下文菜单
- reference
- 学习ExtJs教程初级
- 基于注解配置的Spring MVC 简单的HelloWorld实例应用
- python中property干什么用的?
- 中国首个 SaaS 模式的云告警平台 iOS 版 APP 上线
- State 状态模式
- php常用mysql函数
- python 多线程一(lock)
- BaseServer的介绍
- linkin大话面向对象--初始化块
- BZOJ 4455
- request鉴权的处理和判断
- iqiyi__youku__cookie_设置
- linux 压缩和解压命令
- 关于Unity中的光照(四)
- python-django开发学习笔记一
- network出错
- malloc 函数本身并不识别要申请的内存是什么类型
热门文章
- SQL Server 2008空间数据应用系列四:基础空间对象与函数应用
- H.264 RTPpayload 格式------ H.264 视频 RTP 负载格式
- 使用 ServKit(PHPnow) 搭建 PHP 环境[图]
- 《Qt编程的艺术》——5.1 手动布局
- dom4j解析XML的CURD操作
- Windows下安装Memcache
- .net web api 一
- Android开发_关于点击事件
- WinForm设置控件焦点(转)
- javascript 高级程序设计学习笔记(面向对象的程序设计) 2