二级结构体快排


165A
A. Supercentral Point
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1,?y1),?(x2,?y2),?...,?(xn,?yn). Let's define neighbors for some fixed point from the given set (x,?y):

point (x',?y') is (x,?y)'s right neighbor, if x'?>?x and y'?=?y
point (x',?y') is (x,?y)'s left neighbor, if x'?<?x and y'?=?y
point (x',?y') is (x,?y)'s lower neighbor, if x'?=?x and y'?<?y
point (x',?y') is (x,?y)'s upper neighbor, if x'?=?x and y'?>?y
We'll consider point (x,?y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.

Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.

Input
The first input line contains the only integer n (1?≤?n?≤?200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|,?|y|?≤?1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.

Output
Print the only number — the number of supercentral points of the given set.

Sample test(s)
input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
output
2
input
5
0 0
0 1
1 0
0 -1
-1 0
output
1
Note
In the first sample the supercentral points are only points (1,?1) and (1,?2).

In the second sample there is one supercental point — point (0,?0).

 

 

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 struct ln{
 6     int x;
 7     int y;
 8 }p[205];
 9 int xcmp(const void*a,const void*b)
10 {
11     if((*(struct ln*)a).x==(*(struct ln*)b).x)
12     return (*(struct ln*)a).y>(*(struct ln*)b).y?1:-1;
13     else
14     return (*(struct ln*)a).x>(*(struct ln*)b).x?1:-1;
15 }
16 int ycmp(const void*a,const void*b)
17 {
18     if((*(struct ln*)a).y==(*(struct ln*)b).y)
19     return (*(struct ln*)a).x>(*(struct ln*)b).x?1:-1;
20     else
21     return (*(struct ln*)a).y>(*(struct ln*)b).y?1:-1;
22 }
23 int main()
24 {
25     //freopen("in.txt","r",stdin);
26     int n,k,z=0,i;
27     int q[205],w[205],e[205],r[205];
28     int ymin=0,ymax=0,xmin=0,xmax=0;
29     int t=0,h=0;
30     scanf("%d",&n);
31     for(i=0;i<n;i++)
32     {
33         scanf("%d %d",&p[i].x,&p[i].y);
34         if(p[i].y<ymin)
35         ymin=p[i].y;
36         if(p[i].y>ymax)
37         ymax=p[i].y;
38 
39         if(p[i].x<xmin)
40         xmin=p[i].x;
41         if(p[i].x>xmax)
42         xmax=p[i].x;
43     }
44     qsort(p,n,sizeof(struct ln),ycmp);
45     for(i=0;i<n;i++)
46     {
47         if(p[i].y!=ymin&&p[i].y!=ymax)
48         {
49             if(p[i-1].y==p[i].y&&p[i].y==p[i+1].y)
50             {
51                 q[t]=p[i].x;
52                 w[t]=p[i].y;
53                 t++;
54             }
55         }
56     }
57     qsort(p,n,sizeof(struct ln),xcmp);
58     for(i=0;i<n;i++)
59     {
60         if(p[i].x!=xmin&&p[i].x!=xmax)
61         {
62             if(p[i-1].x==p[i].x&&p[i].x==p[i+1].x)
63             {
64                 e[h]=p[i].x;
65                 r[h]=p[i].y;
66                 h++;
67             }
68         }
69     }
70     for(i=0;i<t;i++)
71     {
72         for(int j=0;j<h;j++)
73         {
74             if(q[i]==e[j]&&w[i]==r[j])
75             z++;
76         }
77     }
78     printf("%d\n",z);
79     return 0;
80 }
View Code

 

转载于:https://www.cnblogs.com/xuesen1995/p/4105788.html

using System; using System.Text; using System.Windows.Forms; using Script.Methods; using System.Collections.Generic; using System.Linq; public partial class UserScript:ScriptMethods,IProcessMethods { int PointXNum; int PointYNum; float [] PointX_input = new float[32]; float [] PointY_input = new float[32]; struct Point //坐标结构体 { public float X; public float Y; } UserScript.Point p = new UserScript.Point(); List<Point> OriginPointList = new List<Point>(); List<Point> SortedPointList = new List<Point>(); List<Point> YSortedPointList = new List<Point>(); List<Point> RowPointList = new List<Point>(); /// <summary> /// Initialize the field's value when compiling /// 预编译时变量初始化 /// </summary> public void Init() { //变量初始化,其余变量可在该函数中添加 } /// <summary> /// Enter the process function when running code once /// 流程执行一次进入Process函数 /// </summary> /// <returns></returns> public bool Process() { //每次执行将进入该函数,此处添加所需的逻辑流程处理 OriginPointList.Clear(); SortedPointList.Clear(); YSortedPointList.Clear(); RowPointList.Clear(); GetFloatArrayValue("in0", ref PointX_input, out PointXNum); GetFloatArrayValue("in1", ref PointY_input, out PointYNum); if (PointXNum != 0 && PointXNum == PointYNum) { for (int i = 0; i < PointXNum; i++) { p.X = PointX_input[i]; p.Y = PointY_input[i]; OriginPointList.Add(p); } } //YSortedPointList = OriginPointList.OrderBy(o => o.Y).ToList(); OriginPointList.Sort(delegate(Point p1,Point p2) //对Y升序排列 { return p1.Y.CompareTo(p2.Y); }); foreach(Point point in OriginPointList)
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值