栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

1-9龟兔赛跑预测

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

1-9龟兔赛跑预测

我的代码

#include
using namespace std;

int T(int v2, int l){
	//乌龟到达终点所需时间
	return l / v2;
}

int R(int v1, int v2, int t, int s, int l){
	//兔子到达终点所需要的时间
	int time1, time = 0, d = 0;		//领先t米花费时间, 跑过的总时间,距离
	while(d < l ){					//越过终点停止
		while(d < v2 * time + t ){	//每秒判断龟兔相对距离,结算
			time++;
			d += v1;
		}
		time += s;
	}
	time -= s + (d - l) / v1;		//把超过终点的时间删去
	return time;
}

int main(){
	int v1, v2, t, s, l;
	cin >> v1 >> v2 >> t >> s >> l;
	if(T(v2, l) < R(v1, v2, t, s, l))
		cout << "T" << endl << T(v2, l);
	else if(T(v2, l) > R(v1, v2, t, s, l))
		cout << "R" << endl << R(v1, v2, t, s, l);
	else
		cout << "D" << endl << T(v2, l);
	return 0;
}

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/717084.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号