本文共 707 字,大约阅读时间需要 2 分钟。
题意:给两种操作:
(1)在表达式中填1;
(2)交换任意两个元素;
要求用最少的操作使字符串构成逆波兰表达式。
思路:贪心。
(1)先让numof(*)==numof(1)-1;
(2)从前往后扫,如果遇到*,numof(*)++;
else numof(1)++;
if numof(*)>=numof(1) 需要把后边的数字交换到前边的*,
即numof(*)--;
numof(1)++;
op++;
#include#include #include #include #include #include #include #include
转载地址:http://nlali.baihongyu.com/