ACM--虫子爬井--模拟--HDOJ 1049--Climbing Worm--水

C语言基本控制结构应用-break语句和continue语句 一条蠕虫长度为1英寸,在一口深为n英寸的井的底部.已知,蠕虫每分钟可以向上爬u英寸,但必须休息一分钟才能接着往上爬,在休息的过程中,蠕虫又向下滑了d英寸。就这样,上爬和下滑重复进行,请问,蠕虫需要多长时间才能爬出井?不足一分钟按一分钟计算,并且假定只要在某次上爬过程中蠕虫的头部到达了井的顶部,那么蠕虫就完成了任务了。初始时候,蠕虫是趴在井底的(即高度为0)。请编写程序模拟蠕虫爬动,求蠕虫爬出时间 立即下载


HDOJ题目地址:传送门


Climbing Worm

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16407    Accepted Submission(s): 11180


Problem Description
An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and resting then repeats. How long before the worm climbs out of the well? We'll always count a portion of a minute as a whole minute and if the worm just reaches the top of the well at the end of its climbing, we'll assume the worm makes it out.
 

Input
There will be multiple problem instances. Each line will contain 3 positive integers n, u and d. These give the values mentioned in the paragraph above. Furthermore, you may assume d < u and n < 100. A value of n = 0 indicates end of output.
 

Output
Each input instance should generate a single integer on a line, indicating the number of minutes it takes for the worm to climb out of the well.
 

Sample Input
  
10 2 1 20 3 1 0 0 0
 

Sample Output
  
17 19

题意:一只虫子从井中往上爬,每分钟爬 u ,休息一分钟,一分钟休息的时候下滑 d ,求最后爬上井的时间。

这是一道巨简单的水题。

#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    //n表示井的深度,u表示虫子每分钟爬多高,d表示虫子每分钟掉多少
    int n,u,d,result;
    while(scanf("%d%d%d",&n,&u,&d)&&n&&u&&d){
        result=0;
        while(1){
            n-=u;
            result++;
            if(n<=0)break;
            n+=d;
            result++;
        }
        printf("%d\n",result);
    }
}



蠕虫C代码 网上找的一个蠕虫代码,对本机影响而以,不会对网络造成影响,研究一下之后可以.不过请注意,我每次运行之后都是把改善出的东西删除了,因为实际作用要在重启之后才会发生作用.慎用! 立即下载

相关推荐

1072青蛙爬井.c

oj题

C语言青蛙爬井(ZZULIOJ1072:青蛙爬井)

注意,不能简单地认为每天上升的高度等于白天向上爬的距离减去夜间下滑的距离,因为若白天能爬出井口,则不必等到晚上。,若青蛙从某个早晨开始向外爬,对于任意指定的high、up和down值(均为自然数),计算青蛙多少天能够爬出井口?每天白天能够沿井壁向上爬up米,夜里则顺井壁向下滑down米。因此我们需要白天爬完后就拿爬的总深度和井的深度进行比较。有一口深度为high米的水井,井底有一只青蛙,它。输入3个正整数:high、up和down。输出一个整数,表示天数。

2301_76828807的博客 1312

在树莓派5(8G版)上运行Ollama + LLM

直接上结论,Ollama在树莓派上能安装,且本身运行起来毫无压力,但具体到大语言模型,Deepseek似乎不总是最佳选择。

ki1381的专栏 1660

爬动的蠕虫

Description 一条蠕虫长度为1厘米,在一口深度为n厘米的井底。已知蠕虫每分钟可以向上爬u厘米,但必须休息1分钟后才能接着往上爬。在休息的过程中,蠕虫又下滑了d厘米。这样反复进行上爬和下滑过程,请求出蠕虫需要多少时间才能爬出井。 假定: 1)初始时蠕虫趴在井底(高度为0); 2)上爬过程中,蠕虫头部到达井的顶部就算出井; 3)计算时间时,不足一分钟按一分钟计算。 Inp

AndyLau96的博客 2380

Replay音频转换时samplerate缺失的解决方案指南

Replay音频转换时提示"No module named 'samplerate' This error is lazily reported, having originally occured in File"的解决方案

weixin_47445543的博客 2155

蓝桥杯算法:打印图形——六芒星

【输入格式】 输入一行包含一个整数 n。 【输出格式】 输出一个六芒星,表示满足题意的图形。 【样例输入】 3 4 【样例输出】 【评测用例规模与约定】 对于所有评测用例,1 ≤ n ≤ 20。 总结: 第一次做图形题,做了蛮久,图形题有很多的方式去完成,它考验的是你能不能找到更简单的那一种方式. 我初看到这个图形,第一种想法是把这个六芒星当做六个小三角形来做,然后以某种规则排列一下,就能做出来,但是尝试了一下感觉太麻烦了。 然后我的第二种想法是,这个图形是对称图形,怎么能写出一半吗? 这样另一半想办

KeepCodeing 3844

【C语言编程】青蛙爬井问题

问题描述 有一口深度为h米的水井,井底有一只青蛙,它每天白天能够沿井壁向上爬m米,夜里则顺井壁向下滑n米,若青蛙从某个早晨开始向外爬,试编写一个函数:对于任意指定的hmn值(均为自然数),计算青蛙多少天能够爬出井口? 问题分析 可以设置两个变量: 1、sum代表青蛙爬的高度,白天加m,晚上减n,如果白天的时候加上m超过了或者等于了h,就代表已经爬出来了,跳出循环就行 2、day代表第n天 代码 因为问题比较简单,直接上代码: #include "stdio.h" int main() { int

Not Found 404 5889

【工具插件类教学】Unity翻书效果插件Book-Page Curl Pro教程

特征: • 从左到右和从右到左翻页 • 与画布缩放器 配合使用 • 可配置的自动翻转脚本 • 支持向页面 添加 UI 元素 • 支持透明页面 • 适用于“世界空间”画布

纯技术流日常开发商业开发记录总结等 3684

c语言:青蛙出井问题程序

c语言关于青蛙可否爬出井的代码

m0_73609765的博客 1745

数据分析案例-电影数据可视化分析

数据介绍数据为2011-2021电影数据可视化分析首先导入本次项目需要的包和数据 数据预处理 可视化

m0_64336780的博客 2万+

华为OD机试 - 素数之积 - 数学问题(Java 2025 A卷 100分)

每一题都有详细的答题思路、详细的代码注释、样例测试,发现新题目,随时更新,全天CSDN在线答疑。

学Java,找哪吒 2135

HDOJ_1049Climbing Worm(爬)

Problem Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, i

Cynical丶Gary_博客 532

innovus:streamOut gds中pg text带有冒号(:)解决办法

streamOut后查看layout,发现部分PG text后面加了冒号,比如VDD: / VSS:。当然,这个问题还有另一种解决办法,就是通过脚本给terminal打text再streamOut。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?

m0_61544122的博客 1196

C语言青蛙出井问题

井底一只青蛙出井,已知井深M米,青蛙每天白天能沿井壁向上爬N米,晚上休息不动,却由于自重下滑K米(假设M&gt;N&gt;K,例如:M=10;N=3;K=1) 编写C语言程序,输出第几天爬出井,累计爬了多少米,下滑了多少米     #include&lt;stdio.h&gt;     /*循环模拟。注意,不能简单地认为每天上升的高度等于白天向上爬的距离减去夜间下滑的距离, 因为若白天能...

良家的博客 7655

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

ZCMU--5218: 青蛙爬井(C语言)

有一口深度为 h 米的水井,井底有一只青蛙,它每天白天能够沿井壁向上爬 a 米,夜里则顺井壁向下滑 b 米,若青蛙从某个早晨开始向外爬,计算青蛙多少天能够爬出井口?第一行包含一个整数T,代表测试数据的组数,接下来 T 行每行包含 3 个正整数h,a,b,含义如题所述。对于每组数据输出一行整数代表答案,若无法爬出井请输出“-1”(不含引号)

小小小Why的博客 1886

深度学习工具包 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")

虫子爬井(有待改进)

/* 虫子在n英寸深的井底,每一分钟爬u英寸,爬下一次要休息一分钟, 在休息的时候虫子会往下滑d英寸,求多长时间虫子能爬出洞口? 在此过程中,分数的小数部分向上取整(其实我没看懂这句话是啥意思) 如果攀爬结束时虫子正好到达井的顶端,视为虫子已经爬出 假定d<u,n<100,当n=0时输入结束 [输入形式] 输入多个测试样例(我觉得这里最难)每行包括3个正整数n,u,d [输出形式] 每个测试用例对

include_645829461的博客 1474

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

循环-07. 爬动的蠕虫(15)

一条蠕虫长1寸,在一口深为N寸的井的底部。已知蠕虫每1分钟可以向上爬U寸,但必须休息1分钟才能接着往上爬。在休息的过程中,蠕虫又下滑了D寸。就这样,上爬和下滑重复进行。请问,蠕虫需要多长时间才能爬出井? 这里要求不足1分钟按1分钟计,并且假定只要在某次上爬过程中蠕虫的头部到达了井的顶部,那么蠕虫就完成任务了。初始时,蠕虫是趴在井底的(即高度为0)。 输入格式: 输入在一行中顺序给

Jason王祖龙 5069

HDU 1049 Climbing Worm

 水题一道~ Problem DescriptionAn inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During

Czy 1221

【 OJ 】 HDOJ1049 模拟蜗牛爬出坑 [ 43 ]

这题模拟就好了....一直模拟u d 到出坑,看结果..当然最简单的还是找规律...用公式来计算...有点烦..懒得找了直接模拟AC了 # include&lt;iostream&gt; using namespace std; int main(void) { int n, u, d; int time , distance; cin &gt;&gt; n &gt;&...

博客 336

c语言 青蛙爬井

/*****题目描述:有一口深度为high米的水井,井底有一只青蛙,它每天白天能够沿井壁向上爬up米,夜里则顺井壁向下滑down米,若青蛙从某个早晨开始向外爬,对于任意指定的high、up和down值(均为自然数),计算青蛙多少天能够爬出井口?   输入:输入3个正整数:high、up和down。   输出:输出一个整数,表示天数。输出单独占一行。   样例:输入:10 2 1 输出:9 ****...

qq_39345244的博客 3517

用C语言解“爬动的蠕虫”题

7-17 爬动的蠕虫 一条蠕虫长1寸,在一口深为N寸的井的底部。已知蠕虫每1分钟可以向上爬U寸,但必须休息1分钟才能接着往上爬。在休息的过程中,蠕虫又下滑了D寸。就这样,上爬和下滑重复进行。请问,蠕虫需要多长时间才能爬出井? 这里要求不足1分钟按1分钟计,并且假定只要在某次上爬过程中蠕虫的头部到达了井的顶部,那么蠕虫就完成任务了。初始时,蠕虫是趴在井底的(即高度为0)。 输入格式: 输入在一行中顺...

weixin_46178942的博客 2126

爬动的蠕虫(C++)

问题描述: 一条虫子在n英寸深的井底,每次一分钟爬行u英寸,但是它再次爬行前必须先休息1分钟,在休息过程中它将滑落d英寸,在反复向上爬行和休息后,多长时间虫子能爬出这口井?在此过程中,分钟的小数部分向上取整,如果攀爬结束时虫子正好到达井口的顶部,则视为虫子已经爬出。假定d<u,n<100,当n=0时输入结束。 输入形式: 输入包括多个测试用例。每行包含3个整数n,u,d,为上面所提到的值。 输出形式: 每个测试用例输入一行,表示虫子爬出井的时间。 样例输入: 10 2 1 20 3 1 0 0

beyond谚语的博客 1532
上一篇: ACM--DFS--最大碉堡数--HDOJ 1045--Fire Net
下一篇: ACM--移动桌子--贪心--HDOJ 1050--Moving Tables
学霸的一天
博客等级 码龄12年 182粉丝 243原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值