题解
2025-09-20 20:07:47
发布于:广东
1阅读
0回复
0点赞
#include <bits/stdc++.h>
#define ll long long
#define ri register int
using namespace std;
struct cows{
int x,y,num;
}c[1100],nth[1100],est[1100];//结构体维护奶牛的信息
//x,y为坐标,num为输入的编号(因为之后要把奶牛存到两个数组里去)
//nth数组是向北走的奶牛的集合,est是向东的
struct point{
int x,y;
int numx,numy;
bool operator < (const point others) const
{
if(this->x == others.x){
return this->y < others.y;
}
return this->x < others.x;
}//重载运算符,当然写比较函数也可
}p[1100 * 1100 /4];//交点维护坐标和相交奶牛的编号
int n,cntn,cnte,cntp,ans[1100];
bool del[1100];//删除数组
int main(void)
{
ios::sync_with_stdio(false);
cin>>n;
for(int i = 1;i <= n;i++){
char x;
cows tmp;
cin>>x>>tmp.x>>tmp.y;
tmp.num = i;
if(x == 'N'){
c[i] = tmp;
nth[++cntn] = tmp;
}
else{
c[i] = tmp;
est[++cnte] = tmp;
}
}//输入不解释
for(int i = 1;i <= cntn;i++){
for(int j = 1;j <= cnte;j++){
if(nth[i].x > est[j].x && nth[i].y < est[j].y){
p[++cntp].x = nth[i].x;
p[cntp].y = est[j].y;
p[cntp].numx = est[j].num;
p[cntp].numy = nth[i].num;
}//建立交点
}
}
sort(p + 1,p + 1 + cntp);
for(int i = 1;i <= cntp;i++){
if(del[p[i].numx] || del[p[i].numy]){
continue;//如果有一头牛被挡住,说明交点不存在了
}
int dx = p[i].x - c[p[i].numx].x;
int dy = p[i].y - c[p[i].numy].y;//计算距离
if(dx < dy){
del[p[i].numy] = 1;
ans[p[i].numx] = ans[p[i].numx] + ans[p[i].numy] + 1;
}
if(dx > dy){
del[p[i].numx] = 1;
ans[p[i].numy] = ans[p[i].numy] + ans[p[i].numx] + 1;
}
}
for(int i = 1;i <= n;i++){
cout<<ans[i]<<endl;
}
return 0;
}
这里空空如也
有帮助,赞一个