这道题目意思很明白,有不确定的数据沙包和陷阱,还要排序···那就必须要用结构体+数组
/*
在地面上有N 个大小不等的长方形陷阱,每个陷阱的周长各不相同,每个参赛者都有一个沙包,闭上眼睛把它扔向地面,
如果沙包掉到了某个陷阱里,那么这个参赛者根据这个陷阱的周长长度(如50米),绕跑道跑陷阱的周长长度(如50米)
如果沙包没有掉到任何一个陷阱里,那么恭喜你,你跑0米。
有m<20000个同学参加了比赛,为了给跑步跑得最多的三位同学(冠军、亚军、季军)颁发安慰奖,
必须给这m个同学的跑的长度按从多到少排序。
如下图一样的坐标系与长方形,这些长方形(陷阱)的四条边都与X轴或Y轴平行,
它们之间互不相交,它们的左上角顶点的坐标与右下角顶点的坐标已知,
给定一个你扔出去的沙包(看作是一个点)的坐标,可以得到你要跑的距离。(注意,这里的坐标值都不超过10000)
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
int cmp(const void *a,const void *b)
{
return *(int *)b-*(int *)a;
}
/*typedef*/ struct point{
int x,y;
}p[20010];
/*typedef */struct tou{
int x1,x2,y1,y2;
int zc;
}t[105];
/*typedef struct note{ //另一种结构体数组定义法
int x,y;
}Note;
typedef struct t{
int x1,x2,y1,y2;
int data;
}T;
T a[105];
Note b[20005]; //落点
int c[20005]; //陷阱
*/
using namespace std;
int main()
{
int c[20010];
int m,n;
int x,y;
int x1,y1,x2,y2;
int i,j;
//int c=0;
scanf("%d%d",&m,&n);//m:同学数量 n:陷阱数量
memset(c,0,sizeof(c));
for(i=0;i<m;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
}
for(j=0;j<n;j++)
{
scanf("%d%d%d%d",&t[j].x1,&t[j].y1,&t[j].x2,&t[j].y2);
t[j].zc=2*((t[j].x2-t[j].x1)+(t[j].y2-t[j].y1));
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(p[i].x>=t[j].x1&&p[i].x<=t[j].x2&&p[i].y>=t[j].y1&&p[i].y<=t[j].y2)
{
c[i]=t[j].zc;
break;
}
}
}
qsort(c,m,sizeof(c[0]),cmp);
for(i=0;i<m;i++)
{
printf("%d\n",c[i]);
}
}