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. IntelliJ IDEA 项目相关的几个重要概念介绍

    必备材料介绍 IntelliJ IDEA 对其他 IDE 转过来的用户有特别优待,对其专门整理了非常棒的资料,还请其他 IDE 过来的用户抽时间查看,会有很大帮助:Eclipse 用户可以看:http ...

  2. leetcode8 String to Integer (atoi)

    题目需求: 输入一个字符串,输出对应的int值 特殊处理: 输入: null  输出:0 输入: "a122"  输出:0 输入: "   1233"  输出: ...

  3. 一个想了好几天的问题——关于8086cpu自己编写9号中断不能单步的问题

           在<汇编语言>第十五章中我们可能遇到这样的问题:程序运行正确,但是debug单步调试,却无法运行,修改int 9h中断例程入口地址的指令,虚拟模式下,debug提示指令无效, ...

  4. Lintcode: Merge Sorted Array II

    Merge two given sorted integer array A and B into a new sorted integer array. Example A=[1,2,3,4] B= ...

  5. 配置suse自动化安装

    配置suse自动化安装 作者:尹正杰   版权声明:原创作品,谢绝转载!否则将追究法律责任.       前言:不知道你习惯用那款虚拟器,我用的是VMware Workstation,别问我为什么,因 ...

  6. 如何抠PSD素材中的图片

    在网上经常可以找到一些好看呢的PSD素材,如何才能将这些素材抠出来 存成一张张的png图片呢? 在PhotoShop中 1·隐藏无用的图层,然后窗口中仅剩需要看到的那个素材图 2·用工具选择该区域(注 ...

  7. 转:Python 的 Socket 编程教程

    这是用来快速学习 Python Socket 套接字编程的指南和教程.Python 的 Socket 编程跟 C 语言很像. Python 官方关于 Socket 的函数请看 http://docs. ...

  8. 关于非阻塞connect的若干细节性问题

    我们用man connection命令查看手册,如下:   EINPROGRESS The socket is nonblocking and the connection cannot be com ...

  9. 玩转HTML5移动页面(动效篇)(转载)

    本文转载自: 玩转HTML5移动页面(动效篇)

  10. paper 23 :Kullback–Leibler divergence KL散度(2)

    Kullback–Leibler divergence KL散度 In probability theory and information theory, the Kullback–Leibler ...