洛谷 P2338 [USACO14JAN]失败的滑雪Bessie Slows Down

45 篇文章 0 订阅

题目背景

奶牛题

题目描述

Bessie the cow is competing in a cross-country skiing event at the winter Moolympic games. She starts out at a speed of 1 meter per second. However, as she becomes more tired over time, she begins to slow down. Each time Bessie slows down, her speed decreases: she moves at 1/2 meter per second after slowing down once, then 1/3 meter per second after slowing down twice, and so on.

You are told when and where Bessie slows down, in terms of a series of events. An event like this:

T 17 means that Bessie slows down at a specific time -- here, 17 seconds into the race. An event like this:

D 10 means that Bessie slows down at a specific distance from the start -- in this case, 10 meters.

Given a list of N such events (1 <= N <= 10,000), please compute the amount of time, in seconds, for Bessie to travel an entire kilometer. Round your answer to the nearest integer second (0.5 rounds up to 1).

贝西正在参加一项滑雪比赛。她从起点出发的时候,速度恒定为每秒 1 米。然而,随着比赛进程的增加,她会犯很多错误,每次失误都会使她的速度下降。当她第一次失误后,速度会下降到每秒1/2 米,第二次失误后,速度会下降到每秒 1/3 米,第 k 次失误后,速度会下降到每秒 1/(k + 1) 米。

约翰记录了贝西的所有失误,一共有 N 个。有两种失误,一种发生在比赛开始后的某个时间点,另一种发生在赛道的某个位置上。有时,贝西可能在某个时间点到达某个位置,而恰好在这个时间点和位置上都有一次失误的记录,这两个记录要算作不同的失误,会对贝西的速度造成两次影响。比赛的终点距离起点有 1000 米,请问贝西需要多少时间才能滑过终点?

输入输出格式

输入格式:

第一行:单个整数 N ,1 ≤ N ≤ 10000

第二行到第 N + 1 行:每行开头有个大写字母,代表贝西的一个失误类型:

– 如果是 T,接下来会有一个整数 S,表示在比赛开始后的第 S 秒钟整发生了一次失误,

1 ≤ S ≤ 10^7

– 如果是 D,接下来会有一个整数 X,表示在距离起点 X 米处发生了一次失误,1 ≤ X ≤

1000

输出格式:

单个整数:表示贝西需要多少秒才能滑到终点,如果精确的时间不是整数,则用四舍五入的方

法向最接近的整数取整

输入输出样例

输入样例#1:
2
T 30
D 10
输出样例#1:
2970

说明

前 10 秒,贝西的速度是每秒 1 米,她滑了 10 米。然后她遭遇了第一次失误,在接下

来的 20 秒内,她又滑了 10 米。之后她遭遇了第二次失误,还剩下 980 米,所以她共计花去

10 + 20 + 2940 = 2970 秒才完成比赛

这么水的模拟,居然难度等级划分到省选-、。。。。。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 20005
double t[maxn],d[maxn],nowt;
int curt,curd,n,speed=1,cpt=1;
//speed 用于记录当前速度
int main(){
	scanf("%d",&n);
	char ch;double x;
	for(int i=1;i<=n;i++){
		cin>>ch;scanf("%lf",&x);
		if(ch=='T') t[++curt]=x;
		else d[++curd]=x;
	}
	d[++curd]=0;d[++curd]=1000;
	sort(d+1,d+curd+1);
	sort(t+1,t+curt+1);
	
	for(int i=1;i<curd;i++){//d的最后一个是1000
		double nowdis=d[i];//当前距离
		while(nowdis<d[i+1]&&cpt<=curt&&nowt+(d[i+1]-nowdis)*speed>t[cpt])
		{// while 的判断条件表示 下一次速度的改变是因为时间
			nowdis+=(t[cpt]-nowt)/speed;speed++;
			nowt=t[cpt++];
		}
		nowt+=(d[i+1]-nowdis)*speed;
		speed++;
	}
	if(nowt-(int)nowt>0.5) nowt=(int)nowt+1;//四舍五入
	else nowt=(int)nowt;
	printf("%.0lf\n",nowt);
	return 0;
}






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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七情六欲·

学生党不容易~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值