P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

题目描述

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<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
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

时间: 2024-11-05 18:52:24

P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver的相关文章

洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 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

洛谷P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

传送门 题目大意:n头牛在单行道n个位置,开始用不同的速度跑步. 当后面的牛追上前面的牛,后面的牛会和前面的牛以一样的速度 跑,称为一个小团体.问:ts后有多少个小团体. 题解:模拟 倒着扫一遍,因为某头牛后面的牛对这头牛的速度没影响. 计算出ts后牛的终点,如果能撞上前面最慢的牛,那么小团体数+1 注意开long long 一开始不理解为什么倒着扫, 因为如果正着扫,看第i头牛能否撞上i+1头, 我们不确定第i+1头牛的速度,可能第i+1头牛 速度很快,追上i+2头牛速度减缓,从而被第i头牛追

[Luogu2901][USACO08MAR]牛慢跑Cow Jogging Astar K短路

题目链接:https://daniu.luogu.org/problem/show?pid=2901 Astar的方程$f(n)=g(n)+h(n)$,在这道题中我们可以反向最短路处理出$h(n)$的精确值.然后跑Astar找K次最短路就好了. 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<queue> 5 using namespace std; 6 int

洛谷P3045 [USACO12FEB]牛券Cow Coupons

P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 86分求救 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget

洛谷 P3014 [USACO11FEB]牛线Cow Line

P3014 [USACO11FEB]牛线Cow Line 题目背景 征求翻译.如果你能提供翻译或者题意简述,请直接发讨论,感谢你的贡献. 题目描述 The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer John. The cows will arrange themselves in a line and ask Far

[USACO12FEB]牛券Cow Coupons(堆,贪心)

[USACO12FEB]牛券Cow Coupons(堆,贪心) 题目描述 Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), and FJ has to spend no more than his budget of M units of money (1 <= M <= 10^14). Cow i costs P_i money (1 <= P_i <= 10^9), b

P2419 [USACO08JAN]牛大赛Cow Contest

P2419 [USACO08JAN]牛大赛Cow Contest 海星 这题代码比较短 (哪题Floyd代码长的) 太真实了 直接上代码吧 这题就是一个经典的传递闭包问题 可以用拓扑排序啥的 不过还是Floyd简便一下 原文地址:https://www.cnblogs.com/qf-breeze/p/10473684.html

牛大赛Cow Contest

题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is unique among the competito

P2952 [USACO09OPEN]牛线Cow Line

题目描述 Farmer John's N cows (conveniently numbered 1..N) are forming a line. The line begins with no cows and then, as time progresses, one by one, the cows join the line on the left or right side. Every once in a while, some number of cows on the left