璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:usaco23feb_cow-libi_s
problems
名称Cow-libi S
题目编号USACO23FEB_S2
题目链接luogu.com.cn/…
来源USACO
算法分类二分
难易程度容易

Cow-libi S

想法

此题最大的难点为读题。把题读懂了这道题就结束了。

使用二分找到时间节点前后的最近作案现场时间与坐标,判断即可。

代码实现

#include<cstdio>
#include<algorithm>
 
struct node{
	long long int x, y, t;
	friend bool operator<(const node a, const node b) {
		return a.t < b.t;
	}
};
 
const int N = 1e5+10;
node line[N];
 
int main() {
	int g, n, cnt = 0;
	long long int x, y, t;
	scanf("%d %d", &g, &n);
	for (int i = 0; i < g; ++i) 
		scanf("%lld %lld %lld", &line[i].x, &line[i].y, &line[i].t);
	std::sort(line, line+g);
 
	for (int i = 0; i < n; ++i) {
		scanf("%lld %lld %lld", &x, &y, &t);
 
		int l=0, r=g-1, mid;
		while(l < r) {
			mid = (l + r) / 2;
			if(t < line[mid].t)
				r = mid;
			else
				l = mid + 1;
		}
		bool flag = false;
		if(l != 0) {
			int temp = l-1;
			if((line[temp].x-x)*(line[temp].x-x) + (line[temp].y-y)*(line[temp].y-y) > (line[temp].t-t)*(line[temp].t-t))
				flag = true;
		}
		if(l != g) {
			if((line[l].x-x)*(line[l].x-x) + (line[l].y-y)*(line[l].y-y) > (line[l].t-t)*(line[l].t-t))
				flag = true;
		}
		if(flag)
			cnt++;
	}
 
	printf("%d", cnt);
	return 0;
}
/app/www/public/data/pages/icpc/problems/usaco23feb_cow-libi_s.txt · 最后更改: 2023/05/02 09:57 由 温婕莺