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. yii中设置提示成功信息,错误提示信息,警告信息

    方法一: <?phpYii::app()->user->setFlash(‘success’,”Data saved!”); 设置键值名为success的临时信息.在getFlash ...

  2. Linux基本命令(6)线上查询的命令

    线上查询的命令 命令 功能 man 查询和解释一个命令的使用方法,以及这个命令的说明事项 locate 定位文件和目录 whatis 寻找某个命令的含义 6.1 man命令 man命令用来查询和解释一 ...

  3. centos7虚拟机无法上网的解决办法

    今天在VMware虚拟机中经过千辛万苦终于安装好了centos7..正兴致勃勃的例行yum update 却发现centos系统貌似默认网卡没配置好,反馈无法联网.经过一番研究,终于让centos连上 ...

  4. JS 实现 ResizeBar,可拖动改变两个区域(带iframe)大小

    将网页化成两个区域,左边区域是一个树结构,右边区域是一个iframe,点击左边区域时,右边区域加载页面.实现功能:在两个区域间加一个可拖动条,拖动时改变左右两个区域的大小.在Google上搜索slid ...

  5. Hadoop-- MapReduce简单理解

    1.Hadoop和MapReduce概念 Mapreduce是一种模式. Hadoop是一种框架. Hadoop是一个实现了mapreduce模式的开源的分布式并行编程框架. 2.Hadoop框架   ...

  6. 面试java简答题

    1.  sleep() 和 wait() 有什么区别? 答:1.这两个方法来自不同的类分别是Thread和Object      2.最主要是sleep方法没有释放锁,而wait方法释放了锁,使得其他 ...

  7. 标准IO

    标准IO由ISO C 标准的IO库,它处理了很多底层细节,比如合适的缓冲大小等等,因此更易于使用,但是也引入了一些其他问题. 流向 标准IO使用FILE对象关联流,流可以是面向宽字节的也可以是面向单字 ...

  8. RequiredFieldValidator的使用

    特別說明:1.一個Button要對頁面的多個控件進行驗證,則需要設置button和其它受控控件的ValidationGroup屬性 aspx頁面實例: <tr class="h&quo ...

  9. 从四大音乐APP首页设计对比分析产品方向

    原帖:http://www.ui.cn/detail/63201.html 本文章中作者例举四个音乐APP应用:虾米.网易.百度.QQ首页 1. 推荐内容:作者将四个首页界面划分出官方推荐与个性化推荐 ...

  10. 远程连接mongodb出现 no route to host 和 Connection refused

    部署好mongodb服务器后,在客户端安装好php的mongodb扩展,用程序连接mongodb服务器出错:no route to host.搜索了差不多一天的时候都没有相关的解决方法.最后在mong ...