bzoj3431 [Usaco2014 Jan]Bessie Slows Down

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).

 

奶牛的初始速度为1m/s,第i次减速后速度为1/(i+1) m/s,给出给定N次减速事件,T x表示在x秒减速,D x表示在离起点x米处减速,减速事件不以时间顺序给出,并且可能同时发生,问跑完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

 

在枚举距离的时候同时更新时间

 

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<algorithm>
 4 #define inf 598460606
 5 using namespace std;
 6 int n,per=1;
 7 int lt,ld,nt=1;
 8 char ch[2];
 9 double t[20000],d[20000],x,nowt;
10 int main()
11 {
12     scanf("%d",&n);
13     for (int i=1;i<=n;i++)
14      {
15         scanf("%s%lf",ch,&x);
16         if (ch[0]=='T')t[++lt]=x;
17         else d[++ld]=x;
18      }
19     d[++ld]=0;
20     d[++ld]=1000;
21     sort(d+1,d+ld+1);
22     sort(t+1,t+lt+1);
23     for(int i=1;i<ld;i++)
24       {
25         double nd=d[i];
26         while (nd<d[i+1]&&nt<=lt&&nowt+(d[i+1]-nd)*per>t[nt])
27         {
28             nd+=(t[nt]-nowt)/per;
29             per++;
30             nowt=t[nt++];
31         }
32         nowt+=(d[i+1]-nd)*per;
33         per++;
34       }
35     if (nowt-(int)nowt>0.5)nowt=(int)nowt+1;
36     else nowt=(int)nowt;
37     printf("%.0lf\n",nowt);
38 }
bzoj3431

 

转载于:https://www.cnblogs.com/zhber/p/4064829.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值