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[ ...
随机推荐
- POJ 1002 487-3279
A - 487-3279 Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- WMI入门
转:http://www.cnblogs.com/ceachy/archive/2013/03/21/WMI_What.html WMI入门(一):什么是WMI WMI出现至今已经二十多年了,但很多人 ...
- C语言 百炼成钢6
//题目16:输入两个正整数m和n,求其最大公约数和最小公倍数. #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include< ...
- 数据爬取ing
ing import urllib for i in range(0,1,1): url='****/GetData?loginName=&userName=&beginDate=20 ...
- 多个相同jar存在时的引用顺序
起因:今天一个aar包在测试环境中正常运行,使用soapui测试正常返回,在本地环境中运行则老是报数据库连接异常,经检查,是因为在运行时环境中缺少ojdbc相关的jar包引起的. 重新打了一个aar包 ...
- java遍历hashTable
//获取key值 Enumeration k = lovResults.keys();while(k.hasMoreElements()){ System.out.println(k.nextElem ...
- IBatis.Net学习笔记五--常用的查询方式
在项目开发过程中,查询占了很大的一个比重,一个框架的好坏也很多程度上取决于查询的灵活性和效率.在IBatis.Net中提供了方便的数据库查询方式. 在Dao代码部分主要有两种方式:1.查询结果为一个对 ...
- 从0开始学java——JSP&Servlet——web容器搜索class的路径顺序
在web应用程序如果要用到某个类,会按照如下的顺序来搜索: 1)在WEB-INF/classes目录下搜索: 2)如果该目录下没有,则会到WEB-INF/lib目录下的jar文件中搜索: 3)如果还没 ...
- [CareerCup] 4.1 Balanced Binary Tree 平衡二叉树
4.1 Implement a function to check if a binary tree is balanced. For the purposes of this question, a ...
- WPF之TreeList的实现方法(一)
做项目的时候根据需求,WPF现有的控件不能完全满足我们的需求, 很多时候我们需要对现有的控件做一下加工. 最简单的我们可能会把Tree转换成List形式有的叫Grid形式就像下图一样 今天我先做一个完 ...