博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
阅读量:5291 次
发布时间:2019-06-14

本文共 2211 字,大约阅读时间需要 7 分钟。

题目描述

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 (1 <= N <= 100,000)头奶牛在一个单人的超长跑道上慢跑,每头牛的起点位置都不同。由于是单人跑道,所有他们之间不能相互超越。当一头速度快的奶牛追上另外一头奶牛的时候,他必须降速成同等速度。我们把这些跑走同一个位置而且同等速度的牛看成一个小组。

请计算T (1 <= T <= 1,000,000,000)时间后,奶牛们将分为多少小组。

输入格式

INPUT: (file cowjog.in)

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: (file cowjog.out)

A single integer indicating how many groups remain after T minutes.

输入输出样例

输入 #1复制
5 3 0 1 1 2 2 3 3 2 6 1
输出 #1复制
3
#include
#include
#include
#include
#include
#include
using namespace std;long long n,t,last[100610];int ans=1;struct cow{ long long spe,pos;}a[100610];long long read(){ long long a=0,b=1; char ch=getchar(); while((ch<48||ch>57)&&ch!='-'){ ch=getchar(); } if(ch=='-'){ b=-1; ch=getchar(); } while(ch<48||ch>57){ ch=getchar(); } while(ch>47&&ch<58){ a=a*10+ch-48; ch=getchar(); } return a*b;}int main(){ n=read(),t=read(); for(int i=1;i<=n;i++){ a[i].pos=read(),a[i].spe=read(); last[i]=a[i].pos+a[i].spe*t; } for(int i=n-1;i>=1;i--){ if(last[i]>=last[i+1]){ last[i]=last[i+1]; } else{     ans++; } } printf("%d",ans);}

  

转载于:https://www.cnblogs.com/xiongchongwen/p/11518034.html

你可能感兴趣的文章
程序员的“机械同感”
查看>>
在16aspx.com上下了一个简单商品房销售系统源码,怎么修改它的默认登录名和密码...
查看>>
c++回调函数
查看>>
linux下Rtree的安装
查看>>
【Java】 剑指offer(53-2) 0到n-1中缺失的数字
查看>>
Delphi中ListView类的用法
查看>>
bzoj3110: [Zjoi2013]K大数查询 【树套树,标记永久化】
查看>>
[原创]Java 的传值小例子
查看>>
【MySQL学习】安装和配置 服务无法启动 没有报告任何错误
查看>>
C# 修饰符
查看>>
JavaScript启示录
查看>>
我需要什么样的浏览器?
查看>>
取textaera里的值
查看>>
java设计模式1--工厂方法模式(Factory Method)
查看>>
博客第一弹—聊聊HTML的那些事
查看>>
上海2017QCon个人分享总结
查看>>
HIVE快速入门 分类: B4_HIVE 2015-...
查看>>
Mysql安装方法及安装问题解决
查看>>
Java动态代理的两种实现方式:
查看>>
PHP trait
查看>>