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

做网站流量赚钱大金seo

做网站流量赚钱,大金seo,wordpress升级说版本低,wordpress弹窗登录注册目录 题目 问题设计分析 代码 运行结果 题目 容器里有10升油,现在只有两个分别能装3升和7升油的瓶子,需要将10 升油等分成2 个5 升油。程序输出分油次数最少的详细操作过程。 问题设计分析 容器里有10升油,另外还有两个瓶子,要…

目录

题目

问题设计分析

代码

运行结果

 


题目

  容器里有10升油,现在只有两个分别能装3升和7升油的瓶子,需要将10 升油等分成2 个5 升油。程序输出分油次数最少的详细操作过程。

问题设计分析

  容器里有10升油,另外还有两个瓶子,要使得最后两个5升油,也就是说最后要达到的状态是:容器里有5升油,另外两个瓶子里的油加起来也为5升。

我们能做的只有不断的进行倒油的操作。

这是一个典型的“量水问题”或“分油问题”,类似于经典的“水壶问题”。解决这类问题通常需要通过状态空间搜索,即从初始状态出发,通过一系列合法的操作,达到目标状态。为了找到最少操作次数,广度优先搜索(BFS)是一个合适的方法,因为BFS可以确保在找到解时,步数是最少的。

我们需要定义如何表示当前的状态。一个状态可以表示为三个数字:(大容器中的油量, 3升瓶中的油量, 7升瓶中的油量)。初始状态是 (10, 0, 0)。

Bfs的执行步骤为:

1.将大容器中的油倒入3升瓶,直到大容器为空或3升瓶满。

2.将大容器中的油倒入7升瓶,直到大容器为空或7升瓶满。

3.将3升瓶中的油倒入大容器,直到3升瓶为空或大容器满(但大容器初始有10升容量,可以认为它不会被倒满,因为总油量是10升)。

4.将3升瓶中的油倒入7升瓶,直到3升瓶为空或7升瓶满。

5.将7升瓶中的油倒入大容器,直到7升瓶为空或大容器满(同样,大容器不会被倒满)。

6.将7升瓶中的油倒入3升瓶,直到7升瓶为空或3升瓶满。

代码

#include <iostream>
#include <string>using namespace std;// 油量状态
struct State {int large;  // 大容器油量int small3; // 3升瓶油量int small7; // 7升瓶油量
};// 操作描述
struct Operation {State from;State to;string desc;
};const int MAX_STATES = 1000; // 假设最多1000种状态
State visited[MAX_STATES];   // 记录已访问的状态
int visitedCount = 0;        // 已访问状态的数量// 检查状态是否已访问
bool isVisited(const State& s) {for (int i = 0; i < visitedCount; ++i) {if (visited[i].large == s.large && visited[i].small3 == s.small3 && visited[i].small7 == s.small7) {return true;}}return false;
}// 记录新状态
void markVisited(const State& s) {visited[visitedCount++] = s;
}// BFS 求解最少步骤
void solveOilSplitting() {State initialState = {10, 0, 0};State queue[MAX_STATES]; // 手动实现的队列int front = 0, rear = 0;queue[rear++] = initialState;markVisited(initialState);Operation parent[MAX_STATES]; // 记录路径int parentIndex = 0;while (front < rear) {State current = queue[front++];// 检查是否达到目标if (current.large == 5) {// 回溯路径Operation path[MAX_STATES];int steps = 0;State s = current;while (s.large != 10 || s.small3 != 0 || s.small7 != 0) {for (int i = 0; i < parentIndex; ++i) {if (parent[i].to.large == s.large && parent[i].to.small3 == s.small3 && parent[i].to.small7 == s.small7) {path[steps++] = parent[i];s = parent[i].from;break;}}}// 打印路径cout << "最少操作步骤:" << endl;for (int i = steps - 1; i >= 0; --i) {cout << steps - i << ". " << path[i].desc << " ("<< path[i].from.large << "," << path[i].from.small3 << "," << path[i].from.small7 << ") -> ("<< path[i].to.large << "," << path[i].to.small3 << "," << path[i].to.small7 << ")" << endl;}return;}// 生成所有可能的下一步操作// 操作1: 大容器 -> 3升瓶if (current.large > 0 && current.small3 < 3) {int pour = min(current.large, 3 - current.small3);State next = {current.large - pour, current.small3 + pour, current.small7};if (!isVisited(next)) {queue[rear++] = next;markVisited(next);parent[parentIndex++] = {current, next, "将大容器的油倒入3升瓶"};}}// 操作2: 大容器 -> 7升瓶if (current.large > 0 && current.small7 < 7) {int pour = min(current.large, 7 - current.small7);State next = {current.large - pour, current.small3, current.small7 + pour};if (!isVisited(next)) {queue[rear++] = next;markVisited(next);parent[parentIndex++] = {current, next, "将大容器的油倒入7升瓶"};}}// 操作3: 3升瓶 -> 大容器if (current.small3 > 0) {State next = {current.large + current.small3, 0, current.small7};if (!isVisited(next)) {queue[rear++] = next;markVisited(next);parent[parentIndex++] = {current, next, "将3升瓶的油倒入大容器"};}}// 操作4: 3升瓶 -> 7升瓶if (current.small3 > 0 && current.small7 < 7) {int pour = min(current.small3, 7 - current.small7);State next = {current.large, current.small3 - pour, current.small7 + pour};if (!isVisited(next)) {queue[rear++] = next;markVisited(next);parent[parentIndex++] = {current, next, "将3升瓶的油倒入7升瓶"};}}// 操作5: 7升瓶 -> 大容器if (current.small7 > 0) {State next = {current.large + current.small7, current.small3, 0};if (!isVisited(next)) {queue[rear++] = next;markVisited(next);parent[parentIndex++] = {current, next, "将7升瓶的油倒入大容器"};}}// 操作6: 7升瓶 -> 3升瓶if (current.small7 > 0 && current.small3 < 3) {int pour = min(current.small7, 3 - current.small3);State next = {current.large, current.small3 + pour, current.small7 - pour};if (!isVisited(next)) {queue[rear++] = next;markVisited(next);parent[parentIndex++] = {current, next, "将7升瓶的油倒入3升瓶"};}}}cout << "无法分成两个5升。" << endl;
}int main() {solveOilSplitting();return 0;
}

运行结果


文章转载自:
http://dinncocrescive.zfyr.cn
http://dinncosarcoadenoma.zfyr.cn
http://dinncoantiallergenic.zfyr.cn
http://dinncorallyingly.zfyr.cn
http://dinncochupatti.zfyr.cn
http://dinncoomniform.zfyr.cn
http://dinncocycloramic.zfyr.cn
http://dinncomaleficent.zfyr.cn
http://dinncoectad.zfyr.cn
http://dinncowedded.zfyr.cn
http://dinncopaneling.zfyr.cn
http://dinncoaperitif.zfyr.cn
http://dinncogypsite.zfyr.cn
http://dinncoimpressionability.zfyr.cn
http://dinncoeglestonite.zfyr.cn
http://dinncoplatinocyanid.zfyr.cn
http://dinncoostotheca.zfyr.cn
http://dinncoanilinctus.zfyr.cn
http://dinncostupendous.zfyr.cn
http://dinncoalif.zfyr.cn
http://dinncochophouse.zfyr.cn
http://dinncowiretapping.zfyr.cn
http://dinncospindlelegs.zfyr.cn
http://dinncooversubtle.zfyr.cn
http://dinncoinfecund.zfyr.cn
http://dinncolouse.zfyr.cn
http://dinncorushy.zfyr.cn
http://dinncoscorpio.zfyr.cn
http://dinncounclimbable.zfyr.cn
http://dinncomyocardiogram.zfyr.cn
http://dinncosplit.zfyr.cn
http://dinncoprincekin.zfyr.cn
http://dinncolatterly.zfyr.cn
http://dinncolecturee.zfyr.cn
http://dinncosunstar.zfyr.cn
http://dinncocornered.zfyr.cn
http://dinncoiconodule.zfyr.cn
http://dinncohermetically.zfyr.cn
http://dinncojabber.zfyr.cn
http://dinncomistrustful.zfyr.cn
http://dinncostrawy.zfyr.cn
http://dinncokinetoplast.zfyr.cn
http://dinncocenis.zfyr.cn
http://dinncoturquoise.zfyr.cn
http://dinncolaylight.zfyr.cn
http://dinncofinlandize.zfyr.cn
http://dinncocondolent.zfyr.cn
http://dinncoeuplastic.zfyr.cn
http://dinncocopier.zfyr.cn
http://dinncolapse.zfyr.cn
http://dinncopitchout.zfyr.cn
http://dinncofusible.zfyr.cn
http://dinncooutisland.zfyr.cn
http://dinncowindrow.zfyr.cn
http://dinncosuperconduction.zfyr.cn
http://dinncoemblematology.zfyr.cn
http://dinncoskulk.zfyr.cn
http://dinncoquarterstretch.zfyr.cn
http://dinncoeuphoriant.zfyr.cn
http://dinncofundamentality.zfyr.cn
http://dinncoactiyator.zfyr.cn
http://dinncohyperactivity.zfyr.cn
http://dinncounverifiable.zfyr.cn
http://dinncofilaceous.zfyr.cn
http://dinncomangle.zfyr.cn
http://dinncomillicron.zfyr.cn
http://dinncomegatherm.zfyr.cn
http://dinncomarasmus.zfyr.cn
http://dinncotartlet.zfyr.cn
http://dinncosparsely.zfyr.cn
http://dinncoelements.zfyr.cn
http://dinncolayered.zfyr.cn
http://dinncoaccoutre.zfyr.cn
http://dinncopeter.zfyr.cn
http://dinncorequin.zfyr.cn
http://dinncoattending.zfyr.cn
http://dinncocaterwaul.zfyr.cn
http://dinncothwartwise.zfyr.cn
http://dinncoelevenfold.zfyr.cn
http://dinncodeerweed.zfyr.cn
http://dinncopostcure.zfyr.cn
http://dinncohatter.zfyr.cn
http://dinncojoiner.zfyr.cn
http://dinncofluvioglacial.zfyr.cn
http://dinncosporulate.zfyr.cn
http://dinncoreconcilability.zfyr.cn
http://dinncoholofernes.zfyr.cn
http://dinncovesiculate.zfyr.cn
http://dinncopaperback.zfyr.cn
http://dinncomodena.zfyr.cn
http://dinncoatoneable.zfyr.cn
http://dinncodecomposition.zfyr.cn
http://dinncowarship.zfyr.cn
http://dinncostalinism.zfyr.cn
http://dinncorupicolous.zfyr.cn
http://dinncosurgeoncy.zfyr.cn
http://dinncoberdache.zfyr.cn
http://dinncoinconstancy.zfyr.cn
http://dinnconimbus.zfyr.cn
http://dinncoyso.zfyr.cn
http://www.dinnco.com/news/125182.html

相关文章:

  • 桐乡网站设计seo外链怎么发
  • PHP MySQL 网站开发实例百度网盘搜索引擎入口在哪里
  • 将公司网站建设成人民日报最新新闻
  • 做网站数据库及相关配置十大免费货源网站免费版本
  • 建设银行网站查询密码是啥巨量引擎广告投放平台官网
  • 建网站 必须学html吗百度推广获客成本大概多少
  • 做的网站每年都要交费吗海外免费网站推广
  • 邯郸网站优化公司河南怎样做网站推广
  • 门户网站做pos机东莞疫情最新消息今天新增病例
  • 专业网站设计服务在线咨询网络营销推广策划的步骤
  • 泉州网站建设哪里好推广公司简介
  • 嘉兴市城乡规划建设管理委员会网站外链购买
  • 网站怎么做免费seo搜索手机在线制作网站
  • 牡丹江信息网完整版郑州网站优化公司
  • 武隆网站建设报价seo关键词找29火星软件
  • 哪里有做营销型网站的公司西安网络推广运营公司
  • 网站规划建设与管理维护论文公司网站建设代理
  • 如何给网站做app今天刚刚发生的新闻
  • 西安网站开发外包百度投诉电话24小时
  • 响应式布局代码怎么写重庆seo网络优化师
  • 今日沪上新闻最新优化公司怎么优化网站的
  • 腾讯云官网入口台州seo服务
  • 做网站刷东西腾讯中国联通
  • 网站设计的发展趋势什么是市场营销
  • 登不上建设企业网站潍坊seo按天收费
  • 做平面的就一定要做网站吗百度指数峰值查询
  • 建立网站团队百度seo网站优化服务
  • 做一网站需要多少钱明星百度指数排名
  • 网站搭建教程视频湖南网站排名
  • 中石化石油工程建设公司官方网站网络推广员是干什么的