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. 【从0到1】android网络框架的选型参考

    项目会使用到 socket tcp 级的网络访问,想选取一个使用较成熟异步网络框架, 提到的网络框架: 1. volley, 2. xutils. 3. android 4. netty, 5. mi ...

  2. 工作流模式与K2实现--(2)

      结构化过程  这两个模式的共同点在于:模式所涉及流程的执行路径是由运行时决定的,而非设计时确定.包括:Arbitrary cycles(强制循环模式) .Implicit termination( ...

  3. JQuery 中 is(':visible') 解析及用法

    实例 选择 <body> 元素中每个可见的元素: $("body :visible") 亲自试一试 定义和用法 :visible 选择器选取每个当前是可见的元素. 除以 ...

  4. oracle中if/else功能的实现的3种写法

    1.标准sql规范 一.单个IF 1. if a=... then ......... end if; 2. if a=... then ...... else .... end if; 二.多个IF ...

  5. [CareerCup] 2.7 Palindrome Linked List 回文链表

    2.7 Implement a function to check if a linked list is a palindrome. LeetCode上的原题,参见我之前的博客Palindrome ...

  6. [CareerCup] 8.10 Implement a Hash Table 实现一个哈希表

    8.10 Design and implement a hash table which uses chaining (linked lists) to handle collisions. 这道题让 ...

  7. 20135208 第一次JAVA实验报告

    课程:Java程序设计          班级: 1352 姓名:贺邦                学号:20135208 成绩:             指导教师:娄嘉鹏       实验日期:2 ...

  8. 利用Gulp优化部署Web项目[长文慎入]

    Gulp Gulp是一款项目自动化的构建工具,与Grunt一样可以通过创建任务(Task)来帮助我们自动完成一些工作流的内容.当然,今天我们的内容并不是讨论这二者的区别,仅仅是介绍介绍如何利用Gulp ...

  9. 0.HBase In Action(HBase实战,翻译)

    1.HBase In Action 第一章-HBase简介(后续翻译中) 2.HBase In Action 第一章-HBase简介(1.1数据管理系统:快速学习) 3.HBase In Action ...

  10. valueOf和toString

    有一道经典的题目: var add = function() {___}; console.log(add(3)(4)(5)); // 输出60 题目要求能无限相乘,请补充add函数. 首先很显然,a ...