BZOJ 3893 Cow Jog
Description
The cows are out exercising their hooves again! There are \(N\) cows jogging on an infinitely-long single-lane track \((1 \le N \le 10^{5})\). Each cow starts at a distinct position on the track, and some cows jog at different speeds. With only one lane in the track, cows cannot pass each other. When a faster cow catches up to another cow, she has to slow down to avoid running into the other cow, becoming part of the same running group. The cows will run for \(T\) minutes \((1 \le T \le 10^{9})\). Please help Farmer John determine how many groups will be left at this time. Two cows should be considered part of the same group if they are at the same position at the end of \(T\) minutes.
在一条无限长的跑道上有\(N\)头牛,每头牛有自己的初始位置及奔跑的速度。牛之间不能互相穿透。当一只牛追上另一只牛时,它不得不慢下来,成为一个群体。求\(T\)分钟后一共有几个群体。
Input
The first line of input contains the two integers \(N\) and \(T\). The following \(N\) lines each contain the initial position and speed of a single cow. Position is a nonnegative integer and speed is a positive integer; both numbers are at most \(1\) billion. All cows start at distinct positions, and these will be given in increasing order in the input.
Output
A single integer indicating how many groups remain after \(T\) minutes.
Sample Input
5 3
0 1
1 2
2 3
3 2
6 1
Sample Output
3
这道题其实不是特别难想(但我TMD还是想WA了。。。QAQ)。
思考一下,如果对于某个奶牛\(p\),如果\(p-1,p-2,...,p-i\)都能追上\(p\),那么这些奶牛在最后都能成为一个整体;否则如果中间有一个\(p-j\)断开了,这个就无法与\(p\)成为一个整体,在\(p-j\)前面也没办法。所以对于\(p-j\)重新考虑。
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long ll;
#define maxn (100010)
#define eps (1e-7)
int N,T,ans,s[maxn],v[maxn];
int main()
{
freopen("3893.in","r",stdin);
freopen("3893.out","w",stdout);
scanf("%d %d",&N,&T);
for (int i = 1;i <= N;++i) scanf("%d %d",s+i,v+i);
for (int i = N;i >= 1;)
{
int p = i; ans++;
for (--i;i&&(s[p]-s[i])<=(ll)(v[i]-v[p])*(ll)T;--i);
}
printf("%d",ans);
fclose(stdin); fclose(stdout);
return 0;
}
BZOJ 3893 Cow Jog的更多相关文章
- 3893: [Usaco2014 Dec]Cow Jog
3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 174 Solved: 87[Submit] ...
- (寒假集训) Cow Jog(二分优化的最长上升子数列)
Cow Jog 时间限制: 1 Sec 内存限制: 64 MB提交: 24 解决: 5[提交][状态][讨论版] 题目描述 Farmer John's N cows (1 <= N < ...
- [BZOJ 3307]Cow Politics (LCA)
[BZOJ 3307]Cow Politics (LCA) 题面 给出一棵N个点的树,树上每个节点都有颜色.对于每种颜色,求该颜色距离最远的两个点之间的距离.N≤200000 分析 显然对于每种颜色建 ...
- Bzoj3893 [Usaco2014 Dec]Cow Jog
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 302 Solved: 157 Description The cows are out exerci ...
- bzoj 3301 Cow Line
题目大意: n的排列,K个询问 为P时,读入一个数x,输出第x个全排列 为Q时,读入N个数,求这是第几个全排列 思路: 不知道康拓展开是什么,手推了一个乱七八糟的东西 首先可以知道 把排列看成是一个每 ...
- [BZOJ 3363] Cow Marathon
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3363 [算法] 树的直径 [代码] #include<bits/stdc++. ...
- BZOJ 4422 Cow Confinement (线段树、DP、扫描线、差分)
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4422 我真服了..这题我能调一天半,最后还是对拍拍出来的...脑子还是有病啊 题解: ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [bzoj3893][Usaco2014 Dec]Cow Jog_暴力
Cow Jog bzoj-3893 Usaco-2014 Dec 题目大意:题目链接. 注释:略. 想法: 先按照坐标排序. 我们发现每个牛只会被后面的牛影响. 所以我们考虑逆向枚举. 记录一下i+1 ...
随机推荐
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(43)-工作流设计-字段分类设计
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(43)-工作流设计-字段分类设计 系列目录 建立好42节的表之后,每个字段英文表示都是有意义的说明.先建立 ...
- 娓娓道来c指针 (3)指针和数组
(3)指针和数组 在c中指针和数组似乎有着千丝万缕的关系.事实上它们不是一回事:指针是指针,数组是数组.两者不同样. 说它们有关系,只是是由于常见这种代码: int main() { int arra ...
- [PWA] Enable Push Notification in your web app
1. Clone the project: git clone https://github.com/GoogleChrome/push-notifications.git 2. install th ...
- Android开发实例-健康食谱应用(一)
转载请注明出处:http://blog.csdn.net/einarzhang/article/details/44774635 本系列文章的重点是如何使用Android开发一个简单的健康食谱软件.使 ...
- android 33 对话框控件
对话框控件:最多3个按钮. mainActivity.java package com.sxt.day05_09; import android.app.Activity; import androi ...
- Qt 学习之路:绘制设备
绘图设备是继承QPainterDevice的类.QPaintDevice就是能够进行绘制的类,也就是说,QPainter可以在任何QPaintDevice的子类上进行绘制.现在,Qt 提供了若干这样的 ...
- Hive数据导入
可以通过多种方式将数据导入hive表 1.通过外部表导入 用户在hive上建external表,建表的同时指定hdfs路径,在数据拷贝到指定hdfs路径的同时,也同时完成数据插入external表. ...
- css 权威指南笔记( 五)结构和层叠
特殊性 重要性 !important; 继承 向上传播例外,应用到body元素的背景样式可以传递到html元素,相应对的可以定义其画布. 大多数框模型属性(包括外边距.内边距.背景.边框)都不能继承 ...
- error: device not found - waiting for device -
执行 cocos run -p android 时报的这个错误 连接上 android 手机, 手机开启开发者模式. 设置--其他高级设置--开发者选项--USB 调试
- 分享一下自己在用的CSS样式重置代码
通过借鉴网上大牛们的经验和自己在工作中碰到的一些问题,总结出了这些比较常用的CSS样式重置的代码: @charset "utf-8"; /* 防止用户自定义背景颜色对网页的影响,添 ...