Escape

Escape
Escape
Escape
自己写的,样例都过了,感觉很对呀,wrong answer on test 4!!

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;

int main()
{
	int vp,vd,t,f,c;
	scanf("%d%d%d%d%d",&vp,&vd,&t,&f,&c);
	
	if(vp>=vd)
	{
		printf("0");
		return 0;
	}
	
	int sp = vp*t;
	int sd = 0;
	int bijous = 0;
	int cnt = 0;
	while(sp<c)
	{
		sp += vp;
		sd += vd;
		cnt++;
		if(sp>=c)
			break;
		
		if(sd>=sp)	//恶龙追上公主 
		{
			bijous++;
			sp += vp*cnt;
			sd -= vd*cnt;
			sp += vp*f;
			cnt = 0;
		}
	}
	
	printf("%d",bijous); 
	return 0;
}

我是一小时一小时模拟的,按整数往后推。。。看过大佬发现可以小数

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>

using namespace std;

int main()
{
	int vp,vd,t,f,c;
	scanf("%d%d%d%d%d",&vp,&vd,&t,&f,&c);
	
	if(vp>=vd)
	{
		printf("0\n");
		return 0;
	}
	
	double sp = t*vp;
	int bijous = 0;
	while(1)
	{
		double time = sp/(vd-vp)*1.0;	//恶龙追上公主所需的时间 
		sp += time*vp;
		
		if(sp>=c)
			break;
		else
		{
			bijous++;
			sp += vp*(f+time);
		}
	}
	
	printf("%d\n",bijous); 
	return 0;
}