Bzoj3893 [Usaco2014 Dec]Cow Jog
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
Output
Sample Input
0 1
1 2
2 3
3 2
6 1
Sample Output
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的更多相关文章
- 3893: [Usaco2014 Dec]Cow Jog
3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 174 Solved: 87[Submit] ...
- [bzoj3893][Usaco2014 Dec]Cow Jog_暴力
Cow Jog bzoj-3893 Usaco-2014 Dec 题目大意:题目链接. 注释:略. 想法: 先按照坐标排序. 我们发现每个牛只会被后面的牛影响. 所以我们考虑逆向枚举. 记录一下i+1 ...
- 3892: [Usaco2014 Dec]Marathon
3892: [Usaco2014 Dec]Marathon Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 169 Solved: 100[Submi ...
- Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 554 Solved: 346[ ...
- BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )
有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )
直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...
- BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )
水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ------------------- ...
- 3891: [Usaco2014 Dec]Piggy Back
3891: [Usaco2014 Dec]Piggy Back Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 116 Solved: 92[Subm ...
- 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 432 Solved: 270[ ...
随机推荐
- XPATH基础入门资料
http://www.w3school.com.cn/xpath/xpath_syntax.asp 不错的网址,入门学习资料
- Apache Shiro(安全框架)
当前常用流行的安全框架主要有两种:一个是Apache Shiro:另一个是Springsource. 现在介绍一下apache shiro: 既然是安全框架,解决的肯定是权限的 控制.所谓权限是指:用 ...
- sqlzoo.net刷题4
SELECT name, continent FROM world a WHERE population > ( FROM world b WHERE a.continent = b.conti ...
- tp空操作和空控制器处理
TP框架几个重要文件:index.php,ThinkPHP.php,Library/Think/Think.class.php,Library/Think/App.class.php,conversi ...
- 【转】【WPF】wpf 图片指针处理
我一直用GDI+做Winform 的基于指针的图片处理,这次下决心全部移到wpf上(主要是显示布局很方便)采用的图片是2512*3307 的大图 830万像素类库基于WritableBitmapEx ...
- The ServiceClass object does not implement the required method in the following form: OMElement sayHello(OMElement e)
今天遇到一件诡异的事情,打好的同一个aar包,丢到测试环境tomcat,使用soapui测试,正常反馈结果. 丢到本地tomcat,使用soapui测试,始终报以下错误. <soapenv:En ...
- sqlalchemy 的 Core 方式使用示例
知乎: sqlalchemy 的 Core 方式操作数据是一种怎样的体验? 答: 爽! 本文基于:win 10 + python 3.4 + sqlalchemy 1.0.13 基本步骤如下: 1. ...
- 在opencv3中利用SVM进行图像目标检测和分类
采用鼠标事件,手动选择样本点,包括目标样本和背景样本.组成训练数据进行训练 1.主函数 #include "stdafx.h" #include "opencv2/ope ...
- 经典趣味24点游戏程序设计(python)
一.游戏玩法介绍: 24点游戏是儿时玩的主要益智类游戏之一,玩法为:从一副扑克中抽取4张牌,对4张牌使用加减乘除中的任何方法,使计算结果为24.例如,2,3,4,6,通过( ( ( 4 + 6 ) - ...
- 一起写一个Android图片加载框架
本文会从内部原理到具体实现来详细介绍如何开发一个简洁而实用的Android图片加载缓存框架,并在内存占用与加载图片所需时间这两个方面与主流图片加载框架之一Universal Image Loader做 ...