杭电 4036

本文探讨了在复杂地形中,如何计算土豆在不同山峰间的滚动速度,以求达到最大速度。通过输入山峰数量、山峰高度、土豆位置、速度和重量等参数,算法计算出土豆在各段路径上的滚动高度,并最终确定整个路径中土豆能达到的最大滚动速度。
#include<stdio.h>
#include<math.h>
#define N 1100
#define g 20
struct mountain
{
	double x,high;
}mountains[N];

struct potato
{
	double x,v,weight;
	double high;
}potatos[N];

int main()
{
	int t,n,m,casea=1;
	double w;
	scanf("%d",&t);
	while(t--)
	{
        
		scanf("%d %d %lf",&n,&m,&w);
        double initv=0.0,temp;
        for(int i=1;i<=n;i++)
		{
			scanf("%lf%lf",&mountains[i].x,&mountains[i].high);
			
			if(mountains[i].high<=mountains[1].high)
				temp=0;
			else
				temp=sqrt(1.0*2*g*(mountains[i].high-mountains[1].high));
			if(temp>initv)
					initv=temp;
		}
        
		for(i=1;i<=m;i++)
		{
			
			scanf("%lf%lf%lf",&potatos[i].x,&potatos[i].v,&potatos[i].weight);
			
			for(int j=1;j<n;j++)
			{
				if(potatos[i].x>=mountains[j].x && potatos[i].x<=mountains[j+1].x)
				{
					potatos[i].high=((potatos[i].x-mountains[j].x)*(mountains[j+1].high-mountains[j].high)/(mountains[j+1].x-mountains[j].x))+mountains[j].high;
					break;
				}
				
			}
		}
		

		for(i=1;i<=m;i++)
		{
		       temp=sqrt(1.0*potatos[i].v*potatos[i].v + 1.0*2*g*(potatos[i].high-mountains[1].high));
			   if(initv<temp)
				   initv=temp;
		}

		printf("Case %d: %.2lf\n",casea++,initv);


		
		
		
	}
	return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值