题目

[USACO14JAN]Bessie Slows Down S

题解

这道题其实蛮简单的,不知道为什么难度划到了提高+,个人觉得这难度大概就是普及左右。

具体说说怎么做吧,简单模拟一下即可,始终记录下当前的时间、位置和速度,每遇到一个失误更新一下,将遇到失误的时间和位置分别排序,然后双指针,找到下一个最近失误的时间和位置,直到所有的失误都结束,最后再将总时间加上剩下的路程/当前速度。

需要注意的是结果四舍五入。

代码

#include<iostream>
#include<algorithm>
using namespace std;
int t[10000], d[10000];
int num_t = 0, num_d = 0;
double len = 0;
double tt = 0; int main()
{
ios::sync_with_stdio(false);
int n;
char c;
int sp = 1;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> c;
if (c == 'D')
cin >> d[num_d++];
else
cin >> t[num_t++];
}
sort(d, d + num_d);
sort(t, t + num_t);
int i = 0, j = 0;
while (i < num_t && j < num_d)
{
double next = 1 / (double)sp * (t[i] - tt)+len;
if (next < d[j])
{
tt = t[i++];
len = next;
sp++;
}
else if (next > d[j])
{
tt += (d[j] - len) * sp;
len = d[j++];
sp++;
}
else
{
tt = t[i++];
len = d[j++];
sp += 2;
}
}
while (i < num_t)
{
len += 1 / (double)sp * (t[i] - tt);
tt = t[i++];
sp++;
}
while (j < num_d)
{
tt += (d[j] - len) * sp;
len = d[j++];
sp++;
}
tt += (1000 - len) * sp;
cout << (int)(tt + 0.5);
return 0;
}

最新文章

  1. 多栏多列布局(display:flex)
  2. android:installLocation 解析
  3. percona-toolkit 之 【pt-deadlock-logger】说明
  4. iOS - OC NSTimer 定时器
  5. Yii 中比较常用的rules验证规则记录
  6. Filter Blue Light for Better Sleep(APP 推荐)
  7. 用Python+Django在Eclipse环境下开发web网站【转】
  8. Cocos2d-x中使用音频CocosDenshion引擎介绍与音频文件的预处理
  9. html input type=&quot;button&quot; 页面跳转
  10. Bzoj 1984: 月下“毛景树” 树链剖分
  11. Linux软件大全
  12. 关于storyboard的一点学习记录
  13. CNN for Visual Recognition (02)
  14. ngx-push-stream模块源码学习(一)——序言
  15. Linux之旅-ubuntu下搭建nodejs环境
  16. EffectiveTensorflow:Tensorflow 教程和最佳实践
  17. 【洛谷P1963】变换序列
  18. pandas列操作集锦
  19. PythonStudy——列表操作 List operatio
  20. [UE4]ProgressBar,进度条

热门文章

  1. jvm源码解读--18 Java的start()方法解读 以及 wait 和notify流程图
  2. spring 读取account-service中的值
  3. &#128293; LeetCode 热题 HOT 100(21-30)
  4. NODEJS对象
  5. Scrapy入门到放弃04:下载器中间件,让爬虫更完美
  6. JavaGUI输入框事件监听的使用
  7. 2021字节跳动校招秋招算法面试真题解题报告--leetcode19 删除链表的倒数第 n 个结点,内含7种语言答案
  8. SaToken学习笔记-03
  9. 手工设置Eclipse文本编辑器的配色
  10. Shell-02-数据类型