ZOJ1005Jugs

Zoj 1005我的解答已经AC ZOJ是一个经典的分油问题,我再这里采用的是广度优先的方法,当然得到的不是最优解,只是一个可行解而已。 立即下载

Jugs

Time Limit: 2000 msMemory Limit: 65536 KB

In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puzzle.

You have two jugs, A and B, and an infinite supply of water. There are three types of actions that you can use: (1) you can fill a jug, (2) you can empty a jug, and (3) you can pour from one jug to the other. Pouring from one jug to the other stops when the first jug is empty or the second jug is full, whichever comes first. For example, if A has 5 gallons and B has 6 gallons and a capacity of 8, then pouring from A to B leaves B full and 3 gallons in A.

A problem is given by a triple (Ca,Cb,N), where Ca and Cb are the capacities of the jugs A and B, respectively, and N is the goal. A solution is a sequence of steps that leaves exactly N gallons in jug B. The possible steps are

fill A 
fill B 
empty A 
empty B 
pour A B 
pour B A 
success

where "pour A B" means "pour the contents of jug A into jug B", and "success" means that the goal has been accomplished.

You may assume that the input you are given does have a solution.

Input

Input to your program consists of a series of input lines each defining one puzzle. Input for each puzzle is a single line of three positive integers: Ca, Cb, and N. Ca and Cb are the capacities of jugs A and B, and N is the goal. You can assume 0 < Ca <= Cb and N <= Cb <=1000 and that A and B are relatively prime to one another.

Output

Output from your program will consist of a series of instructions from the list of the potential output lines which will result in either of the jugs containing exactly N gallons of water. The last line of output for each puzzle should be the line "success". Output lines start in column 1 and there should be no empty lines nor any trailing spaces.

 

Sample Input

3 5 4
5 7 3

Sample Output

fill B
pour B A
empty A
pour B A
fill B
pour B A
success
fill A
pour A B
fill A
pour A B
empty B
pour A B
success
#include<iostream>
using namespace std;
int main()
{
	int ajug, bjug, goal;
	while (cin >> ajug >> bjug >> goal)
	{
		int A = 0, B = 0;
		while (1)
		{
			if (B == goal)
			{
				cout << "success" << endl;
				break;
			}
			if (A  == 0)
			{
				A = ajug;
				cout << "fill A" << endl;
			}
			B += A;
			A = 0;
			cout << "pour A B" << endl;
			if (B >=bjug)
			{
				A = B - bjug;
				B = 0;
				cout << "empty B" << endl;
			}
		}
	}
}

YOLO11实战 第010期-基于yolo11的农业杂草作物目标检测实战文档(详细教程) 通过这条曲线,用户可以评估模型的检测能力,分析模型在不同阈值下对真实目标的检测是否全面。通过这条曲线,可以评估模型在目标检测任务中的整体性能,并找到合适的置信度阈值,以在精确率和召回率之间做出最佳平衡。PR 曲线越接近右上角,模型性能越好,曲线下方的面积越大,说明模型在不同置信度下的。),它展示了不同置信度下的召回率。条曲线都显示了随着召回率的增加,精确度略有下降的趋势,但整体上精确度保持在很高的水平。通过这条曲线,可以选择合适的置信度阈值,以优化模型的检测结果,平衡精确率和召回率。反映了分类器的准确性。 阅读详情

相关推荐

OTFS从零开始11 10

未来的无线网络有望提供全球覆盖,因此需要支持在恶劣环境下的各种新兴应用,例如飞机上的移动通信(MCA)、低地球轨道(LEO)卫星通信、车对车(V2V)通信、高速铁路(HSR)通信、无人驾驶飞机(UAV)通信和水下声学通信(UAC)。在这些恶劣环境中的无线信道通常被视为对通信不友好,其特点是严重的延迟和多普勒扩散,以及有限的路径寿命等。这些不利于通信的特性使目前移动网络中广泛采用的正交频分复用(OFDM)调制的性能恶化。

qq_46009045的博客 9865

zoj1005(广度优先搜索)

题目链接:zoj1005; 这道题是我第一次用广度优先搜索。虽然之前就知道BFS是怎么回事,但是没在具体题目上用过,所以相比DFS,感觉相对生疏。 (虽然这道题网上看到可以用数学方法,很轻松解出;但是为了挑战一下BFS,我还是决定死磕一下) 这道题我看完第一个念头就是搜索。因为每一步就是那几个有限的选择。(虽然题目没说,但是我还是求了最少步骤解出答案的方案,毕竟这种题答案是不唯一的)——考虑...

k0_0k的博客 857

Pinocchio 结合 CasADi 进行 IK 逆运动学及 Mujoco 仿真

摘要:本视频演示了如何利用Pinocchio和CasADi实现机械臂逆运动学(IK)求解,并在Mujoco中进行仿真。通过构建优化问题(最小化位姿误差),结合IPOPT求解器对机械臂关节角度进行优化。代码支持导入URDF/MJCF模型,并以so100机械臂为例,实现了末端执行器位置跟踪的仿真测试。关键步骤包括:建立平移/旋转误差函数、设置约束条件、调用CasADi求解,最终在Mujoco中实时更新关节状态完成运动控制。

darcsdn 1004

ZOJ-1005* 灌水问题

1005:给定两个不同容量的杯子A,B和目标水量,求倒水序列。设A=B) { if(B!=target) { printf("empty B\n"); inA=inB-B; inB=0; } else inB=B; } else { inA=0...

linest 230

2 海康视觉平台VisionMaster 上手系列:大纲及准备

海康视觉平台VisionMaster 大纲,课前准备 快速入门 工业机器视觉 机器视觉

HuangGong2022的博客 1万+

在 CentOS7 下安装 Cadence IC验证平台 INCISIVE152

前言 本文所使用的软件 虚拟机软件:VMware Workstation 15 PRO 如何安装? 操作系统:CentOS-7, CentOS-7-x86_64-DVD-1810.iso 如何安装? 简介 INCISIVE Incisive是nc_verilog, nc_sim, nc_lauch,以及ABV,TBV的集合,用于仿真和验证。 InstallScape InstallSc...

沈醉不知的博客 2万+

zoj-1005倒水问题

题目连接 这题初看起来比较难,有点像dp,又有点像bfs。头晕了!,就是没想到用模拟法,这题真是古怪,我都无语了,大神的代码竟如此简单,一个水题都把我难倒了。 唉!看来分析问题不过正确,没寻找到解题的灵感啊。 这题,你若聪明就可以大致知道这题解题的思路,样列,你是这个解题的出发点。我们想想,要保证你输入的数据有解,我可以可定N 你不可能,直接把b倒满,除非N==Cb,只有用a来实现,先把a

ZXLS-ZMR的专栏 1055

VC Spyglass:Lint实战指南之TCL脚本自动化解析

本文详细介绍了如何利用TCL脚本实现VC Spyglass Lint检查的自动化流程。通过实战指南,从基础脚本编写到高级参数化技巧,帮助数字IC设计工程师摆脱手动操作,提升验证效率,并实现与CI/CD流程的集成。

h3i4j的博客 799

zoj1005解题报告---菜鸟的第一篇解题报告

这是我的第一片解题报告,写的不好的,还望大家指出 zoj1005对于很多人来说是水题目,但是对我来说还是要思考好一会才能做出来的 下面是我的思路,首先那些操作步骤已经定了的,就那么7种,为了省点打字功夫,我存了一个字符串数组 然后就做题目,刚开始只考虑了4种情况,提交后过不了,然后想了很久,找不到原因,之后尝试转化为数学问题,发现了很多情况下有解的,我没有考虑到,而只考虑了集中特殊情况,这个

ACM小菜鸟silence的博客 1313

VC Spyglass实战指南:从零开始掌握CDC约束配置与调试

本文详细介绍了如何使用VC Spyglass进行CDC约束配置与调试,从基础环境搭建到典型CDC问题调试实战,帮助开发者快速掌握跨时钟域验证技术。通过TCL脚本和SDC约束的深度解析,提升CDC验证效率,避免常见设计风险。

weixin_26757925的博客 298

5、硬件工程师笔试面试——上拉电阻、下拉电阻(2025版本)

本文系统介绍了上拉电阻和下拉电阻的原理与应用。上拉电阻通过连接电源确保电路高电平状态,常用于数字电路防抖、OC门驱动等场景;下拉电阻连接地线维持低电平,适用于低电平触发电路。文章详细分析了两种电阻的选择方法、功耗与响应速度的平衡策略,以及在高速信号传输中的影响差异。同时对比了二者的优缺点,并提供了模拟电路中的应用实例。最后给出了电阻值计算的工程方法,为硬件工程师的电路设计提供了实用参考。

XU157303764的博客 2874

ZOJ--1005:Jugs(dfs)

题目大意:两个壶A和B ,可互相倒水,可加满,可倒空,   输入:Ca Cb N              Ca、Cb分别为A B两壶的容量 N为最后B壶所剩水量    输出:操作步骤               pour B A表示从B向A倒水(要么倒满A 要么倒完B) 同理pourA B                                              最后输出succ...

yf224的博客 661

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

ZOJ 1005 Jugs

你可以使用三种类型的操作:(1) 你可以装满一个水罐,(2) 你可以倒空一个水罐,(3) 你可以从一个水罐倒到另一个水罐。例如,如果 A 有 5 加仑,B 有 6 加仑,容量为 8 加仑,那么从 A 倒到 B 会使 B 满,而 A 中会有 3 加仑。程序的输出将由一系列指令组成,这些指令来自可能的输出行列表,这些输出行将导致其中一个水壶恰好装有 N 加仑的水。这个问题概括了该难题。在题目中,我们有两个水壶,分别具有不同的容量,需要通过一系列的操作,最终让其中一个水壶的水量等于给定的目标量(N)。

wuqingshun314159的博客 756

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ZOJ1005 Jugs

Normal 0 7.8 磅 0 2 false false false MicrosoftInternetExplorer4 <!-- /* F

978

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

ZOJ 1005 Jugs 【BFS】

//2634375 2011-08-20 23:33:36 Accepted 1005 C++ 10 23624 ylwh@Unknown #include #include #include #include #include using namespa

我辈皆愚 1103

浙大ZOJ 1005 Jugs问题解决

今天提交的时候有点小郁闷,第一次提交把编译器选错了(选了GCC),太大意了! 一、工程代码及算法设计注释 --------------------------------------------------jugs.h---------------------------------------------- #ifndef JLU_CCST_GDC_JUGS_H #define JLU

xiaogugood的专栏 2000

ZOJ Problem 1005 jugs

题目 In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puz

JetEcho的博客 283

zoj 1005 jugs

  题目内容见zoj1005   由于A,B互素且A的容量小于B,那么可以将B装满并且倒入A中,如果A被装满则将A中的内容全部清空,一直进行下去直到某一刻B中容量恰好等于目标的容量。这种方法能得到正确的结果,但是通常得不到最优结果。   #include &lt;stdio.h&gt; int main(void) { int a,b,target,i; int cu...

codeprac 175

ZOJ Problem Set - 1005 Jugs

Jugs Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were g

acm_1361677193的专栏 427

zoj1005 Jugs

Ca与Cb互质,已经保证有解,解有多种,Special Judge不一定要和Sample一致 //zoj1005 Jugs //Accepted 1005 C++ 00:00.01 392K #include int ca,cb,n; void solve() {        int a,b,bnow;   

fairylan的专栏 1077

zoj1005Jugs

Jugs Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given

hpuzsk的博客 717

ZOJ-1005-Jugs

#include <string> #include <stdio.h> int main(){ int ca, cb, N, nowA, nowB; while(scanf("%d%d%d", &ca, &cb, &N) != EOF){ nowA = 0; nowB = 0; if(cb == N){ printf("...

lengyudota的博客 253
上一篇: ZOJ1004Anagrams by Stack
下一篇: 杭电、POJ、ZOJ ACM刷题顺序和题目分类详解
Lycodeboy
博客等级 码龄11年 1170粉丝 142原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值