版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载。 https://blog.csdn.net/kenden23/article/details/24862581

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

暴力法可过,效率O(n^2)

可是使用hash表能够把效率降到近乎O(n)

要巧妙使用两个map容器。

要对map和set容器非常熟悉了。合起来一起使用。

#include <unordered_map>
#include <set>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
using namespace std; void SupercentralPoint()
{
int n = 0, x, y;
cin>>n;
unordered_map<int, set<int> > xumIS;
unordered_map<int, set<int> > yumIS;
pair<int, int> *pii = new pair<int, int>[n];
for (int i = 0; i < n; i++)
{
cin>>x>>y;
pii[i].first = x;
pii[i].second = y;
xumIS[x].insert(y);
yumIS[y].insert(x);
}
int supers = 0;
for (int i = 0; i < n; i++)
{
if ( pii[i].second != *(xumIS[pii[i].first].begin()) &&
pii[i].second != *(xumIS[pii[i].first].rbegin()) &&
pii[i].first != *(yumIS[pii[i].second].begin()) &&
pii[i].first != *(yumIS[pii[i].second].rbegin()) )
supers++;
}
cout<<supers;
delete [] pii;
}

codeforces A. Supercentral Point 题解的更多相关文章

  1. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

  2. Codeforces Round #545 Div1 题解

    Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...

  3. Codeforces Round #539 Div1 题解

    Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...

  4. [Codeforces Round #461 (Div2)] 题解

    [比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys          [算法] 当y = 0 ,   不可以 当 ...

  5. Codeforces 7E - Defining Macros 题解

    目录 Codeforces 7E - Defining Macros 题解 前言 做法 程序 结尾 Codeforces 7E - Defining Macros 题解 前言 开始使用博客园了,很想写 ...

  6. Educational Codeforces Round 64 部分题解

    Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...

  7. Educational Codeforces Round 64部分题解

    Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...

  8. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  9. Codeforces Good Bye 2016 题解

    好久没有fst题了...比赛先A了前4题然后发现room里有人已经X完题了没办法只能去打E题,结果差一点点打完...然后C题fst掉了结果就掉rating 了...下面放题解 ### [A. New ...

随机推荐

  1. DatacontractSerializer序列化

    DatacontractSerializer在命名空间System.Runtime.Serialization下.它能够序列化DataContract.DataMember标记的类.  一.序列化规则 ...

  2. ExtJs定时消息提示框,类似于QQ右下角提示,ExtJs如何定时向后台发出两个请求并刷新数据实例

    原文出自:https://blog.csdn.net/seesun2012 思路: 1.加载页面,加载Ext.TaskManager.start()方法: 2.执行定时器方法: 3.获取地址向后台发送 ...

  3. 从CentOS官网下载系统镜像详细教程

      很多新手小白鼠想学习CentOS系统,但是不知道镜像去哪里搞,随便去个第三方发现要么要注册,要么各种广告病毒,或者好不容易找到官网,点进去一看却一脸懵逼,不仅全英文,有些专业术语也不懂啊,不要担心 ...

  4. 使用http维持socket长连接

    项目中有遇到问题如下: 1.旧版的cs服务,因为每个用户和唯一的长连接是在登录后绑定的,并且所有的消息报文均是基于该长连接去发送接收的,所以要求node服务要维持一个长连接,然后根据该用户获取长连接, ...

  5. [编程] C语言的结构体

    结构体 struct 结构体名{} 变量名; 结构体变量: struct person{ char *name; int age; float score; } student; 成员的获取和赋值 / ...

  6. [javaSE] 数据结构(二叉树-遍历与查找)

    前序遍历:中,左,右 中序遍历:左,中,右 后序遍历:左,右,中 二叉树查找 从根节点进行比较,目标比根节点小,指针移动到左边 从根节点进行比较,目标比根节点大,指针移动到右边 /** * 前序遍历 ...

  7. C++ 语法积累20161015

    1.break 作用:用于终止当前循环(跳出循环体). 遇到最多的应该是在双层循环体中的使用: (1)在内循环体中,遇到break,则直接跳出内循环体,再次执行外循环体. (2) 在外循环体中,bre ...

  8. 12、springboot注解

    @RestController和@Controller import java.lang.annotation.Documented; import java.lang.annotation.Elem ...

  9. Swift Development – List of Resources You Must Bookmark

    Ever since the introduction of iOS, there is iOS development fever across the globe. Many iOS develo ...

  10. 用CSS3/JS绘制自己想要的按钮

    我认为按钮的绘制分以下三个步骤 第一步,绘制按钮的轮廓 选择合适的html标签,设置轮廓的CSS /* html代码 */ <a href="#" class="b ...