洛谷P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

传送门

题目大意:n头牛在单行道n个位置,开始用不同的速度跑步。

当后面的牛追上前面的牛,后面的牛会和前面的牛以一样的速度

跑,称为一个小团体。问:ts后有多少个小团体。

题解:模拟

倒着扫一遍,因为某头牛后面的牛对这头牛的速度没影响。

计算出ts后牛的终点,如果能撞上前面最慢的牛,那么小团体数+1

注意开long long

一开始不理解为什么倒着扫,

因为如果正着扫,看第i头牛能否撞上i+1头,

我们不确定第i+1头牛的速度,可能第i+1头牛

速度很快,追上i+2头牛速度减缓,从而被第i头牛追上。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#define N 800009
#define LL long long
using namespace std;

LL n,t,ans,now;

struct M{
    LL p,v;
}a[N];

bool cmp(M a,M b){
    return a.p<b.p;
}

int main(){
    scanf("%lld%lld",&n,&t);ans=n;now=n;
    for(int i=1;i<=n;i++)scanf("%lld%lld",&a[i].p,&a[i].v);
    for(int i=n-1;i>=1;i--){
        if(a[i].p+a[i].v*t>=a[now].p+a[now].v*t)ans--;
        else now=i;
    }
    cout<<ans<<endl;
    return 0;
}

时间: 2024-11-10 13:22:55

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

题目描述 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