洛谷 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 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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,t,ans;
long long last[MAXN];
int main(){
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++){
        int pos,v;
        scanf("%d%d",&pos,&v);
        last[i]=pos+1ll*v*t;
    }
    ans=1;
    for(int i=n-1;i>=1;i--){
        if(last[i]>=last[i+1])
            last[i]=last[i+1];
        else    ans++;
    }
    cout<<ans;
}
时间: 2024-10-01 07:09:20

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

洛谷P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

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

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

洛谷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

洛谷P3014 [USACO11FEB]牛线Cow Line

---恢复内容开始--- 关于康托展开 与 康托逆展开 1 #include <bits/stdc++.h> 2 #define For(i, j, k) for(int i=j; i<=k; i++) 3 #define Dow(i, j, k) for(int i=j; i>=k; i--) 4 #define LL long long 5 using namespace std; 6 inline LL read() { 7 LL x = 0, f = 1; 8 char c

洛谷 P2966 [USACO09DEC]牛收费路径Cow Toll Paths

题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The cows move from any of the N (1 <= N <= 250)

洛谷 2966 [USACO09DEC]牛收费路径Cow Toll Paths

https://www.luogu.org/problem/show?pid=2966 题目描述 Like everyone else, FJ is always thinking up ways to increase his revenue. To this end, he has set up a series of tolls that the cows will pay when they traverse the cowpaths throughout the farm. The c

洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom

https://www.luogu.org/problem/show?pid=2863#sub 题目描述 The N (2 <= N <= 10,000) cows are so excited: it's prom night! They are dressed in their finest gowns, complete with corsages and new shoes. They know that tonight they will each try to perform th

洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon

P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W (1 ≤ W ≤ 600) words, each containing no more 25 of the characters 'a'..'z'. Their cowmunication system, based on mooing, is not very accurate; sometime