K
来源:互联网 发布:mac的俄语键盘逗号 编辑:程序博客网 时间:2024/04/29 08:12
题意:给两种操作:
(1)在表达式中填1;
(2)交换任意两个元素;
要求用最少的操作使字符串构成逆波兰表达式。
思路:贪心。
(1)先让numof(*)==numof(1)-1;
(2)从前往后扫,如果遇到*,numof(*)++;
else numof(1)++;
if numof(*)>=numof(1) 需要把后边的数字交换到前边的*,
即numof(*)--;
numof(1)++;
op++;
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <string.h>#include <map>#include <set>#include <queue>#include <deque>#include <list>#include <bitset>#include <stack>#include <stdlib.h>#define lowbit(x) (x&-x)#define e exp(1.0)//ios::sync_with_stdio(false);typedef long long ll;typedef long long LL;using namespace std;int main(){ int T; ios::sync_with_stdio(false); cin>>T; string s; while(T--) { cin>>s; int num = 0,starnum = 0; for(int i=0;i<s.length();i++) { if(s[i]=='*') starnum++; else num++; } int ans = starnum-num+1; if(ans<0) ans = 0; starnum = 0; num = ans; for(int i=0;i<s.length();i++) { if(s[i]=='*') starnum++; else num++; if(starnum>=num) { ans++; starnum--; num++; } } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- k
- k
- k,
- k
- k
- k
- K -
- K
- K
- K
- K
- K
- k
- K
- K
- K
- K
- K
- 【Java核心计算 基础知识(第9版)】第3章 Java的基本程序设计结构
- 收集android上开源的酷炫的交互动画和视觉效果:Interactive-animation
- java新手 if else作业题
- 【51nod 1028】 大数乘法 V2 【FFT/NTT】
- JAVA特性:封装
- K
- hosts文件讲解,以win10系统为例
- 学习日记 第一天
- 二维数组中的查找
- 2017.07.13【NOIP提高组】模拟赛B组
- android系列:第一篇 android开发常用命令集合,代码目录简介
- Codeforces #828A: Restaurant Table 题解
- Mac下python连接mysql数据库
- 数据结构学习系列1-简单单向链表