爬动的蠕虫
来源:互联网 发布:软件实施工程师简历 编辑:程序博客网 时间:2024/04/29 10:07
Description
一条蠕虫长度为1厘米,在一口深度为n厘米的井底。已知蠕虫每分钟可以向上爬u厘米,但必须休息1分钟后才能接着往上爬。在休息的过程中,蠕虫又下滑了d厘米。这样反复进行上爬和下滑过程,请求出蠕虫需要多少时间才能爬出井。
假定:
1)初始时蠕虫趴在井底(高度为0);
2)上爬过程中,蠕虫头部到达井的顶部就算出井;
3)计算时间时,不足一分钟按一分钟计算。
Input
测试数据有多组,每组一行3个数据,第一个表示井深n(0<n<1000),第二个表示蠕虫每分钟上爬距离u(0<u<1000),第三个表示蠕虫每次休息下滑距离d(0<d<1000)。
Output
对应每组输入数据有一行输出数据,当蠕虫能够从深井逃出时,输出其所需要的时间(分种数);当蠕虫不能从深井逃出时,输出提示信息:"The worm can't escape from the well."。
Sample Input
52 50 5
20 67 17
71 37 37
83 40 24
78 67 8
56 12 25
4 37 7
Sample Output
3
1
The worm can't escape from the well.
7
3
The worm can't escape from the well.
#include <stdio.h>#include <iostream>using namespace std;int main(){ int n,u,d,i=0,a[100001]={0},j; while(scanf("%d %d %d",&n,&u,&d)!=EOF) { if(d<u||(u>=n)) { while(n>0) { n=n-u; a[i]++; if(n<=0) break; else { n=n+d; a[i]++; } } } i++; } j=0; while(j<i) { if(a[j]!=0) printf("%d\n",a[j]); else printf("The worm can't escape from the well.\n"); j++; } return 0;}
1
一条蠕虫长度为1厘米,在一口深度为n厘米的井底。已知蠕虫每分钟可以向上爬u厘米,但必须休息1分钟后才能接着往上爬。在休息的过程中,蠕虫又下滑了d厘米。这样反复进行上爬和下滑过程,请求出蠕虫需要多少时间才能爬出井。
假定:
1)初始时蠕虫趴在井底(高度为0);
2)上爬过程中,蠕虫头部到达井的顶部就算出井;
3)计算时间时,不足一分钟按一分钟计算。
测试数据有多组,每组一行3个数据,第一个表示井深n(0<n<1000),第二个表示蠕虫每分钟上爬距离u(0<u<1000),第三个表示蠕虫每次休息下滑距离d(0<d<1000)。
对应每组输入数据有一行输出数据,当蠕虫能够从深井逃出时,输出其所需要的时间(分种数);当蠕虫不能从深井逃出时,输出提示信息:"The worm can't escape from the well."。
#include <stdio.h>#include <iostream>using namespace std;int main(){ int n,u,d,i=0,a[100001]={0},j; while(scanf("%d %d %d",&n,&u,&d)!=EOF) { if(d<u||(u>=n)) { while(n>0) { n=n-u; a[i]++; if(n<=0) break; else { n=n+d; a[i]++; } } } i++; } j=0; while(j<i) { if(a[j]!=0) printf("%d\n",a[j]); else printf("The worm can't escape from the well.\n"); j++; } return 0;}
1
0 0
- 爬动的蠕虫
- 爬动的蠕虫
- 爬动的蠕虫
- 爬动的蠕虫
- 爬动的蠕虫
- 【c++】爬动的蠕虫
- 循环-07. 爬动的蠕虫(15)
- 循环-07. 爬动的蠕虫(15)
- 循环-07. 爬动的蠕虫(15)
- 循环-07. 爬动的蠕虫(15)
- 循环-07. 爬动的蠕虫(15)
- 循环-07. 爬动的蠕虫(15)
- 循环-07. 爬动的蠕虫(15)
- 循环-07. 爬动的蠕虫(15)
- 循环-07. 爬动的蠕虫(15)
- 5-17 爬动的蠕虫
- 5-17 爬动的蠕虫
- PAT17第三组 爬动的蠕虫
- Medium 256题 Paint House
- java删除文件夹
- Math:数学类,提供了一些数学方法
- 《Python学习笔记
- Word Search II解题报告
- 爬动的蠕虫
- STM32启动代码分析
- Spring Boot Servlet
- 计划开始
- js 控制台输出
- Intel的“雄霸之道”,探究编译器对CPU性能的影响
- Java习惯用法总结
- poj-dfs-2531Network Saboteur
- JavaEE----Hibernate初学