532. Building Foundation

题目连接:

http://acm.sgu.ru/problem.php?contest=0&problem=532

Description

A new office building is to appear in Berland soon. Its construction has just been started, and the first problem builders are facing is to lay the foundation.

The ground at construction site area has already been hardened along n segments. Each segment is given by integer coordinates of its endpoints in the site area coordinate system. Every segment has a positive length and is parallel to either Ox axis or Oy axis. It's important to note that the ground hardening was done in such a way that only perpendicular segments could possibly have common points.

The decision has been made for the foundation to have a rectangular form. The rectangle must have the following properties:

it should have a positive area,

its sides should be parallel to one of the coordinate axes,

its sides should be situated on the hardened ground, i.e. each point of its perimeter should belong to at least one segment out of the n hardened ones.

You are to help estimating the difficulty of choosing such a rectangle. Write a program that finds the number of rectangles that can possibly be used as a foundation.

Input

The first line contains integer n (1 ≤ n ≤ 600) — the number of hardened segments. Each of the following n lines contains four space-separated integers x1, y1, x2, y2 (-109 ≤ x1,y1,x2,y2 ≤ 109) — coordinates of the segments' endpoints. Each segment has positive length and is parallel to either Ox axis or Oy axis. No two horizontal segments have a common point. No two vertical segments have a common point.

Output

Print a single integer — the number of rectangles that can possibly be used as a foundation.

Sample Input

4

0 0 1 0

0 0 0 1

1 1 1 -1

1 1 0 1

Sample Output

1

Hint

题意

在平面上给你n条平行于坐标轴的线段,然后问你能够组成多少个矩形

题解:

直接暴力枚举两条边,然后统计有多少条边同时经过这两条边就好了

然后贡献就是n*(n-1)/2,n表示经过这两条边的边数

代码

#include<bits/stdc++.h>
using namespace std;
#define maxn 1005 int x1[maxn],x2[maxn],yy1[maxn],y2[maxn];
int cross(int k1,int k2)
{
if(x1[k1]==x2[k1]&&x1[k2]==x2[k2])
return 0;
if(yy1[k1]==y2[k1]&&y2[k2]==yy1[k2])
return 0; if(yy1[k1]==y2[k1])
swap(k1,k2); if(x1[k1]<=x2[k2]&&x1[k1]>=x1[k2] && yy1[k1]<=yy1[k2]&&y2[k1]>=yy1[k2])
return 1;
return 0;
}
bitset<maxn> s[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&x1[i],&yy1[i],&x2[i],&y2[i]);
if(x1[i]>x2[i])swap(x1[i],x2[i]);
if(yy1[i]>y2[i])swap(yy1[i],y2[i]);
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(cross(i,j))
s[i][j]=1,s[j][i]=1;
long long ans = 0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
bitset<maxn> t = s[i]&s[j];
int p = t.count();
ans+=p*(p-1)/2;
}
cout<<ans/2<<endl;
}

SGU 532. Building Foundation 暴力的更多相关文章

  1. NEERC Southern Subregional 2011

    NEERC Southern Subregional 2011 A - Bonnie and Clyde solution 双指针搞搞就好. 时间复杂度:\(O(n)\) B - Building F ...

  2. Template Method Design Pattern in Java

    Template Method is a behavioral design pattern and it’s used to create a method stub and deferring s ...

  3. cdoj 04 Complete Building the Houses 暴力

    Complete Building the Houses Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/# ...

  4. hdu 5033 Building (单调栈 或 暴力枚举 )

    Description Once upon a time Matt went to a small town. The town was so small and narrow that he can ...

  5. SGU 128. Snake --- 暴力枚举+并查集+贪心+计算几何

    <传送门> 128. Snake time limit per test: 0.25 sec. memory limit per test: 4096 KB There are N poi ...

  6. sgu 142. Keyword 暴力,hash 难度:0

    142. Keyword time limit per test: 0.5 sec. memory limit per test: 16384 KB Kevin has invented a new ...

  7. Building OpenCascade on Windows with Visual Studio

    Building OpenCascade on Windows with Visual Studio eryar@163.com 摘要Abstract:详细说明OpenCascade的编译配置过程,希 ...

  8. ACM 暴力搜索题 题目整理

    UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...

  9. 找规律 SGU 107 987654321 problem

    题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=107 /* 题意:n位数的平方的后面几位为987654321的个数 尼玛,我看描述这 ...

随机推荐

  1. 把raw目录下的几张照片存放到SD卡里面去

    try { //SD卡路径 String filename =android.os.Environment .getExternalStorageDirectory().getAbsolutePath ...

  2. python的元组和列表使用之一

    Python的列表和元组 1.       概述 列表是用方括号[]包围的数据集合,不同的成员之间用逗号进行分隔,列表可以通过序号来进行访问其中的成员,可以对列表进行排序.添加.删除操作,改变列表中某 ...

  3. 免费CDN

    什么是CDN? CDN (Content Delivery Network) ,CDN 是包含可分享代码库的服务器网络. CDN公共库是指将常用的JS库存放在CDN节点,以方便广大开发者直接调用.与将 ...

  4. win7启动出现蓝屏STOP: 0X0000007B

    解决方法:开机进BIOS,更改Interface Combination,即硬盘的接口种类,由默认的RAID改成了AHCI,保存,重启,一切正常. 事件过程: 今天开机进入win7,在start wi ...

  5. remoting blazeds 实施步骤

    remoting 实施步骤 1.创建 --web project 和 -- Flex project 2.在web project 下创建 -- com.HelloRemoting: package ...

  6. HIve体系结构,hive的安装和mysql的安装,以及hive的一些简单使用

    Hive体系结构: 是建立在hadoop之上的数据仓库基础架构. 和数据库相似,只不过数据库侧重于一些事务性的一些操作,比如修改,删除,查询,在数据库这块发生的比较多.数据仓库主要侧重于查询.对于相同 ...

  7. Tmux常用快捷键以及我会常到的一些问题汇总

    今天部署测试服务器环境 使用到了tmux 刚开始我把tmux想象成了像omzsh这种shell 但是被指出是错误的,tmux类似于在shell里面的软件.我还真是第一次接触到这个概念. 首先安装 br ...

  8. 转】启动tomcat时 错误: 代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099的解决办法

    原博文出自于:http://www.cnblogs.com/xdp-gacl/p/5288399.html   感谢! 一.问题描述 今天一来公司,在IntelliJ IDEA 中启动Tomcat服务 ...

  9. Bezier曲线的原理 及 二次Bezier曲线的实现

    原文地址:http://blog.csdn.net/jimi36/article/details/7792103 Bezier曲线的原理 Bezier曲线是应用于二维图形的曲线.曲线由顶点和控制点组成 ...

  10. 【多线程】Java并发编程:Lock(转载)

    原文链接:http://www.cnblogs.com/dolphin0520/p/3923167.html Java并发编程:Lock 在上一篇文章中我们讲到了如何使用关键字synchronized ...