洛谷p2994题解 [USACO10OCT] Dinner Time S

题目描述

Farmer John's N (1 <= N <= 1,000) cows conveniently numbered 1..N are participating in the IOI in Bulgaria. The cows like the Bulgarian sun and are enjoying their holiday. All seems well.

This changes around dinner time. The restaurant is rather small, having only M (1 <= M <= N) cow seats conveniently numbered 1..M. Each cow starts at a location CX_i, (-1,000,000 <= CX_i <= 1,000,000; ); the seats can be found at SX_j, (-1,000,000 <= SX_j <= 1,000,000; ).

The cows have a very efficient (though primitive) method to distribute themselves into the seats. As soon as a cow is certain she will get to a seat first, she rushes there as fast as she can (all cows runs equally fast).

Farmer John's cows, like all prize cows, have no problem jumping over seats, tables, or other cows, so they can run in a straight line. When multiple cows can reach a seat at the very same time, the oldest cow (the one appearing earlier in the input data) gets the seat. Likewise, when a cow can be the first to reach multiple seats she will also choose the one appearing earliest in the input.

Some cows won't be able to eat dinner, and those hungry cows are collectively planning to steal Farmer John's very own food. Farmer John would like a list of cows he should be wary of. (In the case when there are no hungry cows, output 0). Can you help him?

NOTE: Standard distance calculations will likely require an

intermediate result that will fit into a 64-bit integer but not into a 32-bit integer.

输入格式

* Line 1: Two space-separated integers: N and M

* Lines 2..N+1: Line i+1 contains two space separated integers: CX_i and CY_i

* Lines N+2..N+M+1: Line j+N+1 contains two space separated integers: SX_j and SY_j

输出格式

* Lines 1..N-M: Line i contains the number of the ith cow that Farmer John should be wary of. The cow numbers should be listed in increasing order.

题意翻译

题目描述

农场主约翰的 N(1≤N≤10^6)头奶牛被编号为 1∼N,它们正在保加利亚参加 IOI。奶牛们喜欢保加利亚的太阳并享受着它们的假日,一切看起来都没问题。

变化发生在晚餐时间前后。这家餐馆很小,只有 M(1≤M≤N)个座位,编号为 1∼M。每头牛从一个位置 CXi​,CYi 进入餐馆(−10^6≤CXi≤10^6,−10^6≤CYi≤10^6);座位可以在 SXjSXj​,SYjSYj​ 找到(−10^6≤SXj≤10^6,−10^6≤SYj≤10^6)。

奶牛有一种非常有效的(尽管很原始)方法把自己分配到座位上。一旦某只奶牛确定她会先到某个座位上,她就会尽快赶到那里(所有的奶牛都跑得一样快)。

农场主约翰的奶牛和所有获奖的奶牛一样,跳过座位、桌子或其他奶牛都没有问题,因此它们可以直线奔跑。当多头牛可以同时到达一个座位时,最老的牛(在输入数据中出现得更早的牛)获得座位。当一头牛可以第一个到达多个座位时,她也会选择在输入中最早出现的座位。

一些奶牛将不能吃晚饭,这些吃不到饭的饥饿的奶牛正集体计划偷农场主约翰自己的食物。农场主约翰想要一份他应该提防的奶牛名单。(如果没有饥饿的奶牛,则输出 0)。你能帮他吗?

注:在计算中可能会有超过 32 位整数范围但在 64 位整数范围内的数。


输入格式

第一行:两个空格分隔的整数:N 和 M。

第 2∼N+1 行:第 i+1 行包含两个空格分隔的整数:CXi​ 和 CYi。

第 N+2∼N+M+1 行:行 j+N+1 包含两个空格分隔的整数:SXj 和 SYj。


输出格式

第 11 行到第 (N−M) 行:第 i 行包含农场主约翰应该提防的第 i 头牛的编号。奶牛的编号应递增排序。

输入输出样例

输入 #1复制

2 1 
0 1 
1 0 
1 10 

输出 #1复制

2 

思路:

我们考虑暴力求解,我们可以用一个数组来存储这个桌子有没有坐奶牛。

Code:

#include<bits/stdc++.h>
using namespace std;
long long a[1005],b[1005],c,d,flag[1005],pos,dis,mindis=1e15,n,m;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];//输入
	for(int j=1;j<=m;j++){
		cin>>c>>d;//输入
		dis=0,mindis=1e15;
		for(int i=1;i<=n;i++){
			if(flag[i]==1)continue;//如果有牛了,跳出循环
			dis=(a[i]-c)*(a[i]-c)+(b[i]-d)*(b[i]-d);//勾股定理
			if(dis<mindis){
				mindis=dis;//最短距离
				pos=i;//存储下来
			}
		}
		flag[pos]=1;//标记
	}
	if(n==m){//特判
		cout<<0;
		return 0;
	}
	for(int i=1;i<=n;i++){//输出
		if(flag[i])continue;
		cout<<i<<"\n";
	}
}

总结:评绿评高了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值