您的位置:首页 > 其它

bzoj3431【Usaco2014 Jan】Bessie Slows Down

2015-10-25 17:49 471 查看

3431: [Usaco2014 Jan]Bessie Slows Down

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 134  Solved: 64

[Submit][Status][Discuss]

Description

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

Input

* Line 1: The value of N. 
* Lines 2..1+N: Each line is of the form "T x" or "D x", indicating a time event or a distance event. In both cases, x is an integer that is guaranteed to place the event
before Bessie reaches one kilometer of total distance. It is possible for multiple events to occur simultaneously, causing Bessie to slow down quite a bit all at once. Events may not be listed in order.

Output

* Line 1: The total time required for Bessie to travel 1 kilometer.

Sample Input

2

T 30

D 10

INPUT DETAILS: Bessie slows down at time t = 30 and at distance d = 10.

Sample Output

2970

OUTPUT DETAILS: Bessie travels the first 10 meters at 1 meter/second, taking 10 seconds. She then slows down to 1/2 meter/second, taking 20 seconds to travel the next 10 meters. She then reaches the 30 second mark, where she slows down again to 1/3 meter/second.
The remaining 980 meters therefore take her 980 * 3 = 2940 seconds. The total time is therefore 10 + 20 + 2940 = 2970.

HINT

Source

Silver

首先将所有位置和时间从小到大排序。

从小到大枚举每一个位置,判断是先到达此位置还是先到达下一个时间,相应的修改总路程、总时间和速度。

最终输出总时间。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define F(i,j,n) for(int i=j;i<=n;i++)
#define D(i,j,n) for(int i=j;i>=n;i--)
#define MAXN 10050
#define LL long long
using namespace std;
int n,x,p=1,lt=0,ld=0,per=1;
char ch;
double dis,tim=0,d[MAXN],t[MAXN];
int main()
{
scanf("%d",&n);
d[++ld]=0;
d[++ld]=1000;
F(i,1,n)
{
ch=getchar();
while (ch!='T'&&ch!='D') ch=getchar();
scanf("%d",&x);
if (ch=='T') t[++lt]=x;
else d[++ld]=x;
}
sort(t+1,t+lt+1);
sort(d+1,d+ld+1);
F(i,1,ld-1)
{
dis=d[i];
while (dis<d[i+1]&&p<=lt&&tim+(d[i+1]-dis)*per>t[p])
{
dis+=(t[p]-tim)/per;
per++;
tim=t[p++];
}
tim+=(d[i+1]-dis)*per;
per++;
}
tim=(int)(tim+0.5);
printf("%.0lf\n",tim);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: