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. delphi 注册表操作(读取、添加、删除、修改)完全手册

    DELPHI VS PASCAL(87)  32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...

  2. 单机版搭建Hadoop环境图文教程详解

    安装过程: 一.安装Linux操作系统二.在Ubuntu下创建hadoop用户组和用户三.在Ubuntu下安装JDK四.修改机器名五.安装ssh服务六.建立ssh无密码登录本机七.安装hadoop八. ...

  3. 【LeetCode】101 - Symmetric Tree

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  4. 数往知来 AJAX Ajax增删改查<十九>

    =================================================客户端================================================ ...

  5. (转载)OC学习篇之---类的延展

    前一篇文章我们介绍了类的类目概念和使用,那么这篇文章我们继续来介绍一下OC中的一个特性:延展. 其实说白了,延展就是弥补C语言中的前向申明,我们知道,在C语言中,如果你想调用一个函数的话,那么在此之前 ...

  6. AI线性图标教程-转起

  7. Java多线程学习总结--线程同步(2)

    线程同步是为了让多个线程在共享数据时,保持数据的一致性.举个例子,有两个人同时取钱,假设用户账户余额是1000,第一个用户取钱800,在第一个用户取钱的同时,第二个用户取钱600.银行规定,用户不允许 ...

  8. systemd详解

    CentOS 7 使用systemd替换了SysV.Systemd目的是要取代Unix时代以来一直在使用的init系统,兼容SysV和LSB的启动脚本,而且够在进程启动过程中更有效地引导加载服务. s ...

  9. Hadoop概念学习系列之hadoop生态系统闲谈(二十五)

    分层次讲解 最底层平台 ------->hdfs  yarn  mapreduce spark 应用层-------->hbase  hive   pig   sparkSQL    nu ...

  10. 新 esb-cs-tool.jar 参数说明

    旧esb-cs-tool.jar 使用说明 : invoke(RequestBusinessObject requestBo) 旧参数说明: requestBo  : 封装好的请求参数大对象  Req ...