Codeforces Round #112 (Div. 2)---A. Supercentral Point
2 seconds
256 megabytes
standard input
standard 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.
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.
Print the only number — the number of supercentral points of the given set.
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
2
5
0 0
0 1
1 0
0 -1
-1 0
1
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).
解题思路:没什么说的。直接暴力搞了。
遍历每一个点,看是否符合要求。为了省时间,我们能够在输入的时候把x的上限,下限,和y的上限和下限先记录一下,在推断每一个点的时候会用到。
AC代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int x[205], y[205], a[2005][2005]; int main()
{
#ifdef sxk
freopen("in.txt","r",stdin);
#endif
int n, xx, yy, xxx, yyy, flag0, flag1, flag2, flag3;
while(scanf("%d",&n)!=EOF)
{
memset(a, 0, sizeof(a));
xx = yy = -12345;
xxx= yyy = 12345;
for(int i=0; i<n; i++){
scanf("%d%d", &x[i], &y[i]);
x[i] += 1000; y[i] += 1000;
a[x[i]][y[i]] = 1;
if(xx < x[i]) xx = x[i]; //纪录x。y范围
if(xxx > x[i]) xxx = x[i];
if(yy < y[i]) yy = y[i];
if(yyy > y[i]) yyy = y[i];
}
int ans = 0;
for(int i=0; i<n; i++){
flag0 = flag1 = flag2 = flag3 = 0;
for(int j=x[i]+1; j<=xx; j++){ //推断
if( a[j][ y[i] ] ){
flag0 = 1;
break;
}
}
if(flag0){
for(int j=xxx; j<x[i]; j++){
if( a[j][ y[i] ] ){
flag1 = 1;
break;
}
}
if(flag1){
for(int j=y[i]+1; j<=yy; j++){
if( a[x[i]][j] ){
flag2 = 1;
break;
}
}
if(flag2){
for(int j=yyy; j<y[i]; j++){
if( a[x[i]][j] ){
flag3 = 1;
break;
}
}
}
}
}
if(flag3) ans ++;
}
printf("%d\n", ans);
}
return 0;
}
Codeforces Round #112 (Div. 2)---A. Supercentral Point的更多相关文章
- Codeforces Round #112 (Div. 2)
Codeforces Round #112 (Div. 2) C. Another Problem on Strings 题意 给一个01字符串,求包含\(k\)个1的子串个数. 思路 统计字符1的位 ...
- Codeforces Round #112 (Div. 2) D. Beard Graph
地址:http://codeforces.com/problemset/problem/165/D 题目: D. Beard Graph time limit per test 4 seconds m ...
- Codeforces Round #633 (Div. 2)
Codeforces Round #633(Div.2) \(A.Filling\ Diamonds\) 答案就是构成的六边形数量+1 //#pragma GCC optimize("O3& ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- Java面试题之三
十一.谈谈final,finally,finalize的区别? 1.final:是修饰符,是一个关键字.修饰变量,如果是基本类型表示该变量的值不能修改:如果是引用类型表示该变量不能指向别的对象:修饰类 ...
- Objective-C基础教程读书笔记(7)
第7章 深入了解Xcode Xcode是一个很好用的工具,有很多强大的功能,不过并不是所有的功能都易于发现.如果你打算长期使用这个强大的工具,就肯定要尽可能多了解它.本章将介绍一些Xcode编辑器的使 ...
- frame和bounds的区别
frame:根据父视图坐标系来确定自己的位置 bounds:该视图在自己坐标系的位置和大小 修改bounds并不会引起视图位置的变化,会影响自身子视图的位置:修改frame会引起视图位置的变化 UIV ...
- server配置学习 ---- 关闭防火墙
iptables 一种网络防火墙,在LINUX下使用,RedHat9.0版本号以上自带. 它能够实现NAT转换.能够做上网代理. 首先对于server的配置第一步来说就是关闭防火墙.在没有图形化中的l ...
- main函数的参数问题 (转载)
void main(int arg ,char *arv[]){} arg -- 命令行参数总个数arv[0] -- 参数1,程序名 arv[1] -- 参数2,字符串 arv[2] -- 参数3,字 ...
- 【STL__set_的应用】
1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器, 更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结 ...
- 浙江大学2015年校赛B题 ZOJ 3861 Valid Pattern Lock
这道题目是队友写的,貌似是用暴力枚举出来. 题意:给出一组数,要求这组数在解锁的界面可能的滑动序列. 思路:按照是否能够直接到达建图,如1可以直接到2,但是1不能直接到3,因为中间必须经过一个2. 要 ...
- QuartusII 中使用Modelsim对子程序进行仿真
QuartusII 中使用Modelsim对子程序进行仿真 如果采用RTL级仿真那么就没有任何问题,但是如果对子程序采用门级仿真就会出错 解决办法:在Project Navigator中右键需要进行门 ...
- 基于 JVMTI 实现 Java 线程的监控(转)
随着多核 CPU 的日益普及,越来越多的 Java 应用程序使用多线程并行计算来充分发挥整个系统的性能.多线程的使用也给应用程序开发人员带来了巨大的挑战,不正确地使用多线程可能造成线程死锁或资源竞争, ...
- 让Solr返回JSON数据
http://localhost:1985/solr/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on& ...