Counting Rectangles

Time Limit: 1000MS Memory Limit: 10000K

Total Submissions: 1043 Accepted: 546

Description

We are given a figure consisting of only horizontal and vertical line segments. Our goal is to count the number of all different rectangles formed by these segments. As an example, the number of rectangles in the Figures 1 and 2 are 5 and 0 respectively.

There are many intersection points in the figure. An intersection point is a point shared by at least two segments. The input line segments are such that each intersection point comes from the intersection of exactly one horizontal segment and one vertical segment.

Input

The first line of the input contains a single number M, which is the number of test cases in the file (1 <= M <= 10), and the rest of the file consists of the data of the test cases. Each test case begins with a line containing s (1 <= s <= 100), the number of line segments in the figure. It follows by s lines, each containing x and y coordinates of two end points of a segment respectively. The coordinates are integers in the range of 0 to 1000.

Output

The output for each test case is the number of all different rectangles in the figure described by the test case. The output for each test case must be written on a separate line.

Sample Input

2

6

0 0 0 20

0 10 25 10

20 10 20 20

0 0 10 0

10 0 10 20

0 20 20 20

3

5 0 5 20

15 5 15 25

0 10 25 10

Sample Output

5

0

给你水平还有竖直的线段判断可以组成多少的矩形

暴力姿势

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std; const int MAX = 11000; struct node
{
int x1;
int y1;
int x2;
int y2;
}H[120],S[120]; int top1,top2; bool Judge(int h,int s)
{
if(S[s].y1>=H[h].y1&&S[s].y1<=H[h].y2&&H[h].x2>=S[s].x1&&H[h].x2<=S[s].x2)
{
return true;
}
return false;
} int main()
{
int T;
int n;
int x1,y1,x2,y2;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
top1=0;
top2=0;
for(int i=0;i<n;i++)
{
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
if(x1==x2)
{
H[top1].x1=x1;H[top1].y1=min(y1,y2);
H[top1].x2=x2;H[top1].y2=max(y1,y2);
top1++;
}
else if(y1==y2)
{
S[top2].x1=min(x1,x2);S[top2].y1=y1;
S[top2].x2=max(x1,x2);S[top2].y2=y2;
top2++;
}
}
int sum=0;
for(int i=0;i<top1;i++)
{
for(int j=0;j<top2;j++)
{
if(Judge(i,j))
{
for(int k=i+1;k<top1;k++)
{
if(Judge(k,j))
{
for(int s=j+1;s<top2;s++)
{
if(Judge(i,s)&&Judge(k,s))
{
sum++;
}
}
}
}
}
}
}
printf("%d\n",sum);
}
return 0;
}

Counting Rectangles的更多相关文章

  1. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  2. UVA - 10574 Counting Rectangles

    Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...

  3. UVA 10574 - Counting Rectangles(枚举+计数)

    10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保 ...

  4. Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun 四维前缀和

    D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...

  5. Codeforces 372 B. Counting Rectangles is Fun

    $ >Codeforces \space 372 B.  Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...

  6. [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)

    Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...

  7. UVA 10574 - Counting Rectangles 计数

    Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...

  8. Codeforces 372B Counting Rectangles is Fun:dp套dp

    题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...

  9. Codeforces 372B Counting Rectangles is Fun

    http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下 ...

随机推荐

  1. PostgreSQL Replication之第十一章 使用Skytools(5)

    11.5 关于walmgr 的介绍 walmgr 是一个简化基于文件事务日志传输的工具.早在过去的一些日子里(在9.0版本之前),使用walmgr来简化基本备份是很常见的.随着流复制的引入,情况有了一 ...

  2. [原创]java WEB学习笔记73:Struts2 学习之路-- strut2中防止表单重复提交

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  3. UML: 活动图

    摘自http://www.umlonline.org/school/thread-36-1-1.html 活动图和流程图很类似,我们看看一个流程图的例子: 活动图是用来描述流程的一种图,它与流程图的不 ...

  4. 判断java中两个对象是否相等

    java中的基本数据类型判断是否相等,直接使用"=="就行了,相等返回true,否则,返回false. 但是java中的引用类型的对象比较变态,假设有两个引用对象obj1,obj2 ...

  5. 构造方法特点,void

    构造方法特点: 1.和类有相同的名字 2.无返回值 3.被默认强制void void作用:====>>说明声明的方法没有返回值 构造方法作用: -->初始化实例属性 -->用于 ...

  6. 从C#的Singleton设计模式

    近来,我在学习如何在C#语言中使用设计模式中读到一些资料,其中有关Singleton设计模式引起了我的注意. 学过设计模式的开发者都知道Singleton模式.我想简要地解释一下这个设计模式是为那些尚 ...

  7. Spark on Yarn

    Spark on Yarn 1. Spark on Yarn模式优点 与其他计算框架共享集群资源(eg.Spark框架与MapReduce框架同时运行,如果不用Yarn进行资源分配,MapReduce ...

  8. 静态关键字static

    //静态关键字的使用static //类里面的普通成员是属于对象的,不是属于类的(调用的时候是用对象调用) //什么叫做静态的:类静态成员是属于类的,不是属于每个对象的 //定义静态成员用static ...

  9. [Sinatra、Mongo] Mongo

    Mongo is a document-oriented database. Install the required gems: gem install mongo gem install bson ...

  10. Loadrunner教程读后感-VuGen

    一.loadrunner协议分析 协议确定方法 二.提交表单函数的区别 (1)web_sumit_form() (2)web_sumit_data() 三.web_url和web_link 四.VuG ...