codeforces A. Supercentral Point 题解

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 题解,布布扣,bubuko.com

时间: 2024-10-06 05:56:39

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

codeforces New Year Present 题解

The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception. Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a r

codeforces Sereja and Dima 题解

Sereja and Dima play a game. The rules of the game are very simple. The players have n cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take o

codeforces D. Ice Sculptures 题解

The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures

Educational Codeforces Round 64部分题解

Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点个数是否有限,如果有限,输出. 很明显当正方形套三角形或者三角形套正方形是交点个数是无限的(因为有一条边相交) 其他图形的嵌套交点个数比较好判断,不多赘述 但是注意坑点: 当按照矩形,园,三角这样的顺序是,三角与圆的一个交点是与圆和正方形的交点重合的,判一下就好了 #include<cstdio>

Codeforces 7E - Defining Macros 题解

目录 Codeforces 7E - Defining Macros 题解 前言 做法 程序 结尾 Codeforces 7E - Defining Macros 题解 前言 开始使用博客园了,很想写点东西.(逃 这是一道Codeforces题目. 做法 一道大模拟 相信大家都看得懂题目意思,我就不赘述了. 首先我们读进来\(n\)行,对于每一行,我们把它初步分成一下四块内容: #号 define 宏的名字 宏的表达式 注意:#和define中间可能会有空格,define和宏的名字,宏的名字和宏

Codeforces Round #616 部分题解

老年选手诈尸? A,B 咕了. C - Prefix Enlightenment 很容易看出这个限制条件可以推出每个点最多被两个集合包含.按照套路,很容易联想到给这两个集合连一条边,表示他们的状态要相同/不同. 因为保证了有解,所以从左往右扫的时候拿并查集维护一下每个连通块的二分图情况,选较小的那一边. 如果只被一个集合覆盖,那么就相当于强制这个集合选/不选,在做并查集的时候特判一下即可. 代码咕了. D - Coffee Varieties (hard version) 作为一名憨憨,做法当然

【codeforces】【比赛题解】#854 CF Round #433 (Div.2)

cf一如既往挺丧 看丧题点我! [A]分数 Petya是数学迷,特别是有关于分数的数学.最近他学了所谓一个分数被叫做"真分数"当且仅当其分子小于分母,而一个分数被叫做"最简分数"当且仅当其分子分母互质.在闲暇时间,Petya在用计算器研究:如何把最简真分数转换为小数等问题.有一天他不小心把除号(÷)按成了加号(+),导致他得到了分子与分母的和.Petya想要得到他原来的分数,但他很快发现这不是唯一的.所以现在他想要知道最大的最简真分数使得其分子与分母的和为n. 输入

Codeforces #Round 376 部分题解

A: 题目传送门:http://codeforces.com/problemset/problem/731/A 直接根据题意模拟即可 1 #include "bits/stdc++.h" 2 3 using namespace std ; 4 typedef long long QAQ ; 5 6 char s[ 1010 ] ; 7 8 inline int Calc ( const char x , const char y ) { 9 if ( x > y ) return

Codeforces A. Double Cola 题解

题目很奇怪,就是5个人排队喝可乐,喝完之后编程两个人,然后拍在队后面,然后继续喝可乐. 给出个数值,代表第几罐可乐,问会是第几个人喝到? http://codeforces.com/problemset/problem/82/A 一个数学问题,仔细点就好了. 要熟练的知识点: 1 要熟悉解决这种递增数列,如何减去循环部分 2 要知道如何计算,求余取答案 #include <string> #include <iostream> using namespace std; void D