Codeforces 148B: Escape

题目链接:http://codeforces.com/problemset/problem/148/B

题意:公主从龙的洞穴中逃跑,公主的速度为vp,龙的速度为vd,在公主逃跑时间t时,龙发现公主逃跑并开始追公主。公主每丢弃一块宝石,龙需要花f小时整理并送回洞穴,然后再去追公主,公主在离洞穴距离为c的时候就安全了,求公主在逃跑过程中需要丢弃的宝石数

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
using namespace std;
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	int vp,vd,t,f,c;
	cin>>vp>>vd>>t>>f>>c;
	int ans=0;
	// 注意公主速度不小于龙的速度的情况
	if(vp>=vd)
		cout<<ans<<endl;
	else
	{
		double x=vp*t*1.0;
		int v=vd-vp;
		double t1;
		while(1)
		{
			t1=x/v;
			x+=t1*vp;
			// 如果在龙整理宝石的过程中,公主已经到安全区域
			if(x>=c)
				break;
			else
			{
				ans++;
				x+=(f+t1)*vp;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/wang_123_zy/article/details/81132817