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).
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
T 30
D 10
INPUT DETAILS: Bessie slows down at time t = 30 and at distance d = 10.
Sample Output
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
在枚举距离的时候同时更新时间
#include<cstdio>
#include<cmath>
#include<algorithm>
#define inf 598460606
using namespace std;
int n,per=;
int lt,ld,nt=;
char ch[];
double t[],d[],x,nowt;
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++)
{
scanf("%s%lf",ch,&x);
if (ch[]=='T')t[++lt]=x;
else d[++ld]=x;
}
d[++ld]=;
d[++ld]=;
sort(d+,d+ld+);
sort(t+,t+lt+);
for(int i=;i<ld;i++)
{
double nd=d[i];
while (nd<d[i+]&&nt<=lt&&nowt+(d[i+]-nd)*per>t[nt])
{
nd+=(t[nt]-nowt)/per;
per++;
nowt=t[nt++];
}
nowt+=(d[i+]-nd)*per;
per++;
}
if (nowt-(int)nowt>0.5)nowt=(int)nowt+;
else nowt=(int)nowt;
printf("%.0lf\n",nowt);
}
bzoj3431
bzoj3431 [Usaco2014 Jan]Bessie Slows Down的更多相关文章
- BZOJ3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 55 So ...
- 3433: [Usaco2014 Jan]Recording the Moolympics
3433: [Usaco2014 Jan]Recording the Moolympics Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 137 S ...
- 洛谷P2338 Bessie Slows Down S 题解
题目 [USACO14JAN]Bessie Slows Down S 题解 这道题其实蛮简单的,不知道为什么难度划到了提高+,个人觉得这难度大概就是普及左右. 具体说说怎么做吧,简单模拟一下即可,始终 ...
- BZOJ 3432: [Usaco2014 Jan]Cross Country Skiing (二分+染色法)
还是搜索~~可以看出随着D值的增大能到达的点越多,就2分d值+染色法遍历就行啦~~~ CODE: #include<cstdio>#include<iostream>#incl ...
- 【BZOJ】3433: [Usaco2014 Jan]Recording the Moolympics (贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=3433 想了好久啊....... 想不出dp啊......sad 后来看到一英文题解......... ...
- 【BZOJ】3432: [Usaco2014 Jan]Cross Country Skiing (bfs+二分)
http://www.lydsy.com/JudgeOnline/problem.php?id=3432 题目说要相互可达,但是只需要从某个点做bfs然后判断其它点是否可达即可. 原因太简单了.... ...
- BZOJ 3433 [Usaco2014 Jan]Recording the Moolympics:贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3433 题意: 给出n个区间[a,b). 有两个记录器,每个记录器中存放的区间不能重叠. 求 ...
- BZOJ 3430: [Usaco2014 Jan]Ski Course Rating(并查集+贪心)
题面 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 136 Solved: 90 [Submit][Status][Discuss] Descript ...
- 【bzoj 3433】{Usaco2014 Jan} Recording the Moolympics(算法效率--贪心)
题意:给出n个区间[a,b),有2个记录器,每个记录器中存放的区间不能重叠.求2个记录器中最多可放多少个区间. 解法:贪心.只有1个记录器的做法详见--关于贪心算法的经典问题(算法效率 or 动态规划 ...
随机推荐
- Android Toast简介
Toast是Android中一种提供给用户简短信息的视图,该视图已浮于应用程序之上的形式呈现给用户.因为它并不获得焦点,即使用户正在输入什么也不会受到影响.它的目标是尽可能以不显眼的方式,使用户看到你 ...
- [置顶] API相关工作过往的总结之Sandcastle简要使用介绍
Sandcastle介绍 在微软推出Sandcastle之前,人们倾向于选择开源的NDoc(.NET代码文档生成器).NDo可以将 C#.NET 编译生成的程序集和对应的 /doc XML文档,自动转 ...
- Win32/MFC的基本概念
一.MFC的基本概念 单文档.多文档和对话框框架的区别 MFC中的类继承图的基本框架 CView类与CDocument的关系 Onpaint()和Ondraw()的关系 hdc-cdc区别联系 RUN ...
- (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(2)
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选的第二部分,其余章节将陆续放出.上一 ...
- hibernate-4.3.5安装配置
起初照着官方文档配,一直出错,貌似官方的文档时错的,查了非常多资料,综合整理了一个可行的方案,例如以下: 0.1包结构 test.demo test.domain //实体类 test.util// ...
- [hihocoder 1033]交错和 数位dp/记忆化搜索
#1033 : 交错和 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 给定一个数 x,设它十进制展从高位到低位上的数位依次是 a0, a1, ..., an - 1 ...
- 高性能MySql进化论【转】
高性能MySql进化论(十二):Mysql中分区表的使用总结 http://binary.duapp.com/category/sql 当数据量非常大时(表的容量到达GB或者是TB),如果仍然采用索引 ...
- Difference between enabled and userInteractionEnabled properties
I read through the documentation, and here are my findings. UIButton inherits from UIControl the boo ...
- 实现简单的django上传文件
本文用django实现上传文件并保存到指定路径下,没有使用forms和models,步骤如下: 1.在模板中使用form表单,因为这个表单使用于上传文件的,所以method属性必须设置为post,而且 ...
- JavaScript 中的事件设计
1. 事件绑定的几种方式 主要介绍一下 最常用的事件设计 其他就稍微带过. 直接在代码里面添加onclick指定函数名字. B) 在JS代码中通过dom元素的onclick等属性 这种做法this表 ...