您的位置:首页 > 其它

BZOJ 3893 Usaco2014 Dec Cow Jog 模拟

2015-02-27 18:24 357 查看
题目大意:给出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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: