BZOJ 3893 Usaco2014 Dec Cow Jog 模拟

题目大意:给出n头牛他们的初始位置和各自的速度,一头牛追上另一头牛之后这两头牛会变成一头牛,问最后剩下几头牛。

思路:简单模拟一下不难发现,我们只要算出如果正常行驶每头牛的最后到达的地点,从后往前扫一下,有多少个单调不减的序列就是最后有多少头牛。

CODE:

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 100010
#define INF 1e18
using namespace std;

int cnt;
long long x,y,t,src[MAX];

int main()
{
	cin >> cnt >> t;
	for(int i = 1; i <= cnt; ++i) {
		scanf("%lld%lld",&x,&y);
		src[i] = x + y * t;
	}
	int ans = 0;
	long long last = INF;
	for(int i = cnt; i; --i)
		if(src[i] < last) {
			last = src[i];
			++ans;
		}
	cout << ans << endl;
	return 0;
}

时间: 2024-10-13 08:52:28

BZOJ 3893 Usaco2014 Dec Cow Jog 模拟的相关文章

BZOJ 3893 [Usaco2014 Dec]Cow Jog

题目大意:给定一些牛,每头牛有一个初始位置和速度,如果某头牛能追上后面的那头速度就会和后面那头一样,求T分钟后会形成多少小团体 <论排序算法的低效性和如何避免使用排序算法以及认真读题的重要性> 一头牛的速度不会被后面的牛所影响 因此我们从后往前扫,如果当前的牛追不上后面那个小团体中最慢的那头牛,这头牛就成为新的小团体 时间复杂度O(n) 注意数据有点问题,虽然说初始位置和速度都小于等于100W但是实际上有比这个大的 #include <cstdio> #include <cs

3893: [Usaco2014 Dec]Cow Jog

3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 174  Solved: 87[Submit][Status][Discuss] Description The cows are out exercising their hooves again! There are N cows jogging on an infinitely-long single-lane track (1 <= N

Bzoj3893 [Usaco2014 Dec]Cow Jog

Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 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

BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )

水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ---------------------------------------------------------------------------------- #include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; ++i) #define clr(x

BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )

直接从每个奶牛所在的farm dfs , 然后算一下.. ---------------------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<vector> #define rep( i ,

BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )

有点类似背包 , 就是那样子搞... ------------------------------------------------------------------------------------ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ;  i < n ; ++i

BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐

Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is grazing in one of N (1 <= N <= 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 <= M <= 10,000) one-way paths (no p

BZOJ 3892 Usaco2014 Dec Marathon DP

题目大意:给出平面上的一些点,要求按顺序遍历,费用是两点之间的曼哈顿距离,可以跳过k次,问最少需要花费多少. 思路:O(n^3)dp就行了. CODE: #define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 510 using namespace std; struct

BZOJ 3891 Usaco2014 Dec Piggy Back BFS

题目大意:给出一张无向图,有两个人,分别在1和2,他们要到n,一个人走的消耗是c1,c2,两个人一起走是c3,问最少消耗. 思路:题中说是可以一起走,而不是必须一起走,所以之需要看这两个人到所有点的距离,还有每个点到终点的距离,之后枚举从那个点开始一起走,求一下最小值就可以了. CODE: #define _CRT_SECURE_NO_WARNINGS #include <queue> #include <cstdio> #include <cstring> #incl