当前位置: 首页 > news >正文

深圳找做兼职女上班的网站怎么宣传自己的产品

深圳找做兼职女上班的网站,怎么宣传自己的产品,最大的地方门户网站源码,免费网站建设 百度一下题目链接:According to Bartjens 题目描述: 给定一个由数字和一个组成的字符串,你需要在数字之间添加,−,∗,-,*,−,∗三种符号,在保证表达式合法的情况下(同时形成的新的数字不能有前导零),使表…

题目链接:According to Bartjens
题目描述:

给定一个由数字和一个===组成的字符串,你需要在数字之间添加+,−,∗+,-,*+,,三种符号,在保证表达式合法的情况下(同时形成的新的数字不能有前导零),使表达式的结果等于200020002000,输出所有可能的添加方案(你至少要添加一个符号),按照字典序从小到大进行输出。
例如2100100=2100100=2100100=的解如下:
在这里插入图片描述

题解:

本题只知道至少添加一个符号,所以我们需要依次枚举添加一个、两个、三个一直到n−2n-2n2个(nnn为表达式的长度),然后使用DFSDFSDFS尝试在每个位置放置符号,放置的时候需要注意不能出现含有前导零的数字,保证不出现前导零有两种方案:

  • 枚举所有位置,在最后进行检查的时候判断出现在计算符号之后的数字以000开头但是位数大于111
  • 在搜索的过程中进行判断,假定搜索到位置pospospos如果当前位置是000那么当前位置的后面只能放置非数字符号;

如何计算表达式的值?可以使用逆波兰表达式,具体的使用两个栈,一个用来保存数字,一个用来保存符号,符号站里面的符号的优先级要保证递增:

  • 遇到数字则直接加入数字栈;
  • 遇到符号的时候,检查符号与符号栈栈顶的符号的优先级,如果栈顶的符号优先级较高或相等,那么则应该弹出栈顶的符号进行一次计算,直到符号栈为空,或者栈顶的符号优先级较低,再将当前的符号入栈;
  • 最后弹出符号栈里面的所有符号依次进行计算。

代码:

#include <bits/stdc++.h>const int NaN = 0x3f3f3f3f;
const int OPERATOR_NUM = 3;using namespace std;int maxDepth, caseID;
string expression, now;
char ope[] = "*+-";
vector<string> ans;// 比较两个运算符的优先级
int cmp(char op1, char op2)
{if (op1 == op2) { return 0; }if (op1 == '*') { return 1; }if (op2 == '*') { return -1; }return 0;
}// 计算两个数的和、差或者积
int calculate(int lhs, char ope, int rhs)
{if (ope == '+') { return lhs + rhs; }if (ope == '-') { return lhs - rhs; }return lhs * rhs;
}bool check()
{int num = NaN, lhs = 0, rhs = 0;stack<int> number;stack<char> ops;for (int i = 0; i < now.length() - 1; i++) {if (isdigit(now[i])) {if (num == NaN) { num = 0; }num = num * 10 + now[i] - '0';} else {number.push(num);while (!ops.empty() && cmp(ops.top(), now[i]) >= 0) {rhs = number.top(); number.pop();lhs = number.top(); number.pop();number.push(calculate(lhs, ops.top(), rhs));ops.pop();}ops.push(now[i]);num = NaN;}}if (num != NaN) { number.push(num); }while (!ops.empty()) {rhs = number.top(); number.pop();lhs = number.top(); number.pop();num = calculate(lhs, ops.top(), rhs); ops.pop();number.push(num);}return number.top() == 2000;
}void dfs(int nowDepth, int pos)
{if (nowDepth == maxDepth) {int tempLen = now.length();int increment = expression.length() - pos;now.append(expression.substr(pos, increment));if (check()) { ans.push_back(now); }now.erase(tempLen, increment);return;}if (maxDepth - nowDepth > expression.length() - 2 - pos) { return; }for (int i = pos; i < expression.length() - 2; i++) {// 这里是保证最后一个数字不含有前导零if (nowDepth == maxDepth - 1 && expression[i + 1] == '0' && expression[i + 2] != '=') { continue; }for (int j = 0; j < OPERATOR_NUM; j++) {int tempLen = now.length();int increment = i - pos + 1 + 1;now.append(expression.substr(pos, i - pos + 1));now.push_back(ope[j]);dfs(nowDepth + 1, i + 1);now.erase(tempLen, increment);}// 这里保证当前数字不含前导零,当前数字如果是以0开头那么不能继续进行拼接if (expression[pos] == '0') { break; }}
}int main()
{while (cin >> expression) {ans.resize(0);now = "";if (expression[0] == '=') { break; }for (maxDepth = 1; maxDepth < expression.length() - 1; maxDepth++) { dfs(0, 0); }caseID++;cout << "Problem " << caseID << endl;sort(ans.begin(), ans.end());for (auto str : ans) { cout << "  " << str << endl; }if (ans.size() == 0) { cout << "  IMPOSSIBLE" << endl; }}return 0;
}
http://www.hkea.cn/news/48850/

相关文章:

  • 外贸五金网站建设网站制作优化排名
  • 义乌网站建设多少钱网络平台营销
  • 怀仁有做网站的公司吗磁力搜索引擎2023
  • 建站行业都扁平化设计合肥网站推广公司哪家好
  • 做企业网站织梦和wordpress哪个好百度指数查询工具app
  • 郑州网站服务公司优化神马排名软件
  • 茶叶网站建设的优势南宁seo外包平台
  • 高古楼网站 做窗子北京seo技术交流
  • 南阳建设网站制作网络最有效的推广方法
  • 纯静态网站seoseo排名优化北京
  • 开封网站建设哪家好指数计算器
  • 网站开发 架构石家庄seo关键词排名
  • 可以免费做商业网站的cms百度seo霸屏软件
  • 哪家网站建设专业快速建站教程
  • 坪山网站建设行业现状优化seo方案
  • 做网站需要架构师吗网站平台有哪些
  • 网站建设丿选择金手指15凡科建站官网
  • 可以做外国网站文章武汉企业seo推广
  • 天津网站建设公司最好太原做网站哪家好
  • 网站代下单怎么做百度指数数据分析平台入口
  • 淘宝做动效代码的网站seo的优化方向
  • 番禺建网站公司网站搜索工具
  • 安徽万振建设集团网站长春网站推广公司
  • 网站怎么制作 推广seo超级外链工具免费
  • 中小学网站建设探讨东莞seo整站优化火速
  • php是网站开发的语言吗企业网站的作用
  • 网站站外优化怎么做企业推广app
  • 拉趣网站是谁做的威海网站制作
  • 做宣传海报的网站百度导航2023年最新版
  • 湖南做网站 磐石网络windows优化大师官方免费