Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 302  Solved: 157

Description

The cows are out exercising their hooves again! There are N cows jogging on an infinitely-long single-lane track (1 <= N <= 100,000). 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 <= T <= 1,000,000,000). 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

HINT

 

Source

先按初始顺序给牛编号,然后让牛跑T分钟,按照新位置从小到大排序(位置相同的,序号大的在前)。

然后从前往后扫一遍,如果编号小的牛跑到的位置比编号大的牛远,那么实际上他们已经合并了。

记录从1开始的编号单增序列长度就是答案。

从别的博客(辗转山河弋流歌)看到了更短的写法:从后往前扫一遍,看哪些牛撞死了

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
const int mxn=;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL v[mxn],p[mxn];
LL id[mxn];
int n;LL T;
int cmp(int a,int b){
if(p[a]==p[b])return a>b;
return p[a]<p[b];
}
int main(){
n=(LL)read();
T=read();
int i,j;
for(i=;i<=n;i++){
p[i]=read();v[i]=read();
p[i]+=v[i]*T;
}
for(i=;i<=n;i++)id[i]=i;
sort(id+,id+n+,cmp);
int last=,ans=;
for(i=;i<=n;i++){
if(id[i]>last){ans++;last=id[i];}
}
printf("%d\n",ans);
return ;
}

Bzoj3893 [Usaco2014 Dec]Cow Jog的更多相关文章

  1. 3893: [Usaco2014 Dec]Cow Jog

    3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 174  Solved: 87[Submit] ...

  2. [bzoj3893][Usaco2014 Dec]Cow Jog_暴力

    Cow Jog bzoj-3893 Usaco-2014 Dec 题目大意:题目链接. 注释:略. 想法: 先按照坐标排序. 我们发现每个牛只会被后面的牛影响. 所以我们考虑逆向枚举. 记录一下i+1 ...

  3. 3892: [Usaco2014 Dec]Marathon

    3892: [Usaco2014 Dec]Marathon Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 169  Solved: 100[Submi ...

  4. Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 346[ ...

  5. BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )

    有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...

  6. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )

    直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...

  7. BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )

    水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...

  8. 3891: [Usaco2014 Dec]Piggy Back

    3891: [Usaco2014 Dec]Piggy Back Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 116  Solved: 92[Subm ...

  9. 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 432  Solved: 270[ ...

随机推荐

  1. java 12-3 StringBuffer的添加和删除功能

    1. StringBuffer的添加功能: public StringBuffer append(String str):可以把任意类型数据添加到字符串缓冲区里面,并返回字符串缓冲区本身 public ...

  2. windows系统命令服务安装卸载

    安装: sc create PDW.CHM.WebAPI binPath= "%~dp0PDW.CHM.WebAPI.exe" start= autosc start PDW.CH ...

  3. CLR Profiler

    检查c#代码内存泄露工具-CLR Profiler 大家都知道.net有一套自己的内存(垃圾)回收机制,除非有一些数据(方法)长期占有内存不随着垃圾回收功能而释放内存,这样就造成了我们经常说的内存泄露 ...

  4. wireshark添加ip.id字段

    wireshark添加ip.id字段 为了在多个设备上追踪同一个数据包. 如果是同一个会话,则可以计算延迟, 如sta和应用服务器慢,这种问题,可以根据这个加上ip.id追踪数据到哪里慢了.    

  5. jacob下载问题, Office word 此文件正由另一应用程序或用户使用的解决方法

    http://jingyan.baidu.com/article/75ab0bcbd6682fd6864db2db.html

  6. Unity小知识

    这些是我在开发时遇到的一些问题: 2D的碰撞器和3D的碰撞器是没有任何物理反应的,必须是2D对2D,3D对3D 碰撞器Collision包含触发物体的速度等信息,触发器没有

  7. .NET Core手记 - Json.NET的使用

    Json.NET大家很熟悉了,很流行的高性能Json库,很棒的是Json.NET也支持了.NET Standard框架,也就意味着我们可以在.NET Core项目里使用了. 创建一个.NET Core ...

  8. Promise 学习笔记 - 时间支配者

    本文同步自我的个人博客:http://www.52cik.com/2015/11/08/promise.html JavaScript 的 promises 事实标准称为 Promises/A+.ES ...

  9. ionic 项目笔记

    最近公司在用ionic 做 微站,项目中难免遇到一些问题.总结如下: 1.       改了Slidebox 动态绑定图片时,页面会显示一片空白,改变窗口大小的时候,图片就出来了,说明动态绑定图片时, ...

  10. 谈谈iOS9中的WebKit 与 Safari

    每个用过 UIWebView 的iOS开发者对其诸多的限制和有限的功能也深有感触.悻然,自iOS8推出 WebKit 框架后将改变这一窘境.在本文我将会深入WebKit来体验一下它给我们带来的好处,同 ...