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. HDU5808Price List Strike Back (BestCoder Round #86 E) cdq分治+背包

    严格按题解写,看能不能形成sum,只需要分割当前sum怎么由两边组成就好 #include <cstdio> #include <cstring> #include <c ...

  2. CSS框架分析与网站的CSS架构

    框架(framework)是一个基本概念上的结构,用于去解决或者处理复杂的问题,是一种可复用的构架. 我们对CSS框架这个词比较陌生,但对于JavaScript框架就比较熟悉了,比如jQuery 但为 ...

  3. js 判断字符是否以汉字开头

    javascript代码如下: var re = new RegExp("^[\u4e00-\u9fa5]"); if (re.test("aaa好")) { ...

  4. Java核心_内省

    Java核心_内省 查看java的api,发现有一个包java.bean咦,这个包是干什么的呢,原来,它是用来操作JavaBean对象的! 一.内省操作①JavaBean:一种特殊的Java类无参构造 ...

  5. 对人脑处理视觉的描述(摘《学习OpenCV(中文版)》)

    人脑将视觉信号划分入很多个通道,将各种不同的信息输入你的大脑.你的大脑有一个关注系统,会根据任务识别出图像的重要部分,并做重点分析,而其他部分则分析得较少 .在人类视觉流中存在大量的反馈,但是目前我们 ...

  6. 数往知来 HTML<十一>

    HTML_CSS <!--一.表单   <form></form>    表单就是用来进行数据提交的标签 表单就是一对<form></form>标 ...

  7. Excel的 OleDb 连接串的格式

    Excel的 OleDb 连接串的格式(Provider=Microsoft.ACE.OLEDB)(2012-08-02 13:04:20) string strCon = "Provide ...

  8. 1、Hadoop架构

    1.Hadoop 是一个能够对大量数据进行分布式处理的软件框架,实现了Google的MapReduce编程模型和框架,能够把应用程序分割成许多小的工作单元放到任何集群节点上执行. 作业(job):一个 ...

  9. 如何申请TexturePacker注册码

    TexturePacker是一款很强大的游戏图片制作工具,网上有很多关于它的教程和说明,这里不再说它的作用和好处.这里只是说一下如何申请免费的注册码. 国人都习惯了使用免费或者破解的软件,但是使用破解 ...

  10. 简单版问卷调查系统(Asp.Net+SqlServer2008)

    1.系统主要涉及以下几个表  问卷项目表(Q_Naire) 问卷题目表(Q_Problem) 题目类型表(Q_ProblmeType) 题目选项表(Q_Options) 调查结果表(Q_Answer) ...