排位赛3-Race

排位赛3-Race

题目

Bessie is running a race of length K (1≤K≤109) meters. She starts running at a speed of 0 meters per second. In a given second, she can either increase her speed by 1 meter per second, keep it unchanged, or decrease it by 1 meter per second. For example, in the first second, she can increase her speed to 1 meter per second and run 1 meter, or keep it at 0 meters per second and run 0 meters. Bessie’s speed can never drop below zero.
Bessie will always run toward the finish line, and she wants to finish after an integer amount of seconds (ending either at or past the goal line at this integer point in time). Furthermore, she doesn’t want to be running too quickly at the finish line: at the instant in time when Bessie finishes running K meters, she wants the speed she has just been traveling to be no more than X (1≤X≤105) meters per second. Bessie wants to know how quickly she can finish the race for N (1≤N≤1000) different values of X.

题意

bessie在进行一场k米长的赛跑,她一开始速度为1m/s,它可以自由提速或降速1m/s,在冲线时她希望用了整数秒并且冲线的速度不超过xm/s,问最短用时,有多组数据。

解法

其实这道题不难,模拟即可,用时最短当然时一直提速当提速超过x时,就开始对称(画个v-s图就知道了)从终点开始同步速度,直到总路程超过k就完成了。

代码:

#include <cstring>
#include <algorithm> 
#include <queue>
#include <cstring>
#include <iostream>
#include <stdio.h> 
using namespace std;
int L,n,x,nl,temp,v,ans;

int main() 
{
	scanf("%d%d",&L,&n);
	for (int i=1;i<=n;i++) 
	{
		scanf("%d",&x);
		nl=0;
		temp=0;
		v=1;
		ans=0;
		while (1) 
		{
			nl+=v;
			ans++;
			if (nl+temp>=L) 
			{
				break;
			}
			if (v>=x) 
			{
				temp+=v;
				ans++;
				if (nl+temp>=L) 
				{
					break;
				}
			}
			v++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值