洛谷P2338 Bessie Slows Down S 题解
2024-09-07 20:52:40
题目
[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;
}
最新文章
- 多栏多列布局(display:flex)
- android:installLocation 解析
- percona-toolkit 之 【pt-deadlock-logger】说明
- iOS - OC NSTimer		定时器
- Yii 中比较常用的rules验证规则记录
- Filter Blue Light for Better Sleep(APP 推荐)
- 用Python+Django在Eclipse环境下开发web网站【转】
- Cocos2d-x中使用音频CocosDenshion引擎介绍与音频文件的预处理
- html input type=";button"; 页面跳转
- Bzoj 1984: 月下“毛景树” 树链剖分
- Linux软件大全
- 关于storyboard的一点学习记录
- CNN for Visual Recognition (02)
- ngx-push-stream模块源码学习(一)——序言
- Linux之旅-ubuntu下搭建nodejs环境
- EffectiveTensorflow:Tensorflow 教程和最佳实践
- 【洛谷P1963】变换序列
- pandas列操作集锦
- PythonStudy——列表操作 List operatio
- [UE4]ProgressBar,进度条