Counting Rectangles
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的更多相关文章
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
- UVA - 10574 Counting Rectangles
Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...
- UVA 10574 - Counting Rectangles(枚举+计数)
10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保 ...
- 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 ...
- Codeforces 372 B. Counting Rectangles is Fun
$ >Codeforces \space 372 B. Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...
- [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)
Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...
- UVA 10574 - Counting Rectangles 计数
Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...
- Codeforces 372B Counting Rectangles is Fun:dp套dp
题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...
- Codeforces 372B Counting Rectangles is Fun
http://codeforces.com/problemset/problem/372/B 题意:每次给出一个区间,求里面有多少个矩形 思路:预处理,sum[i][j][k][l]代表以k,l为右下 ...
随机推荐
- PostgreSQL与RPM
如何查看使用PostgreSQL的RPM包安装后的文件目录及相关路径(PostgreSQLRPM的spec文件已经帮我们创建好了postgres用户及postgres组). 查看RPM文档信息:/us ...
- Groupon面经Prepare: Max Cycle Length
题目是遇到偶数/2,遇到奇数 *3 + 1的题目,然后找一个range内所有数字的max cycle length.对于一个数字,比如说44,按照题目的公式不停计算,过程是 44, 22, 11, 8 ...
- chat
启动服务器 连接数据库 导入数据库并显示 开启监听 与客户端建立连接 写入数据库并显示 创建线程用来接受客户端消息
- 某个点到其他点的曼哈顿距离之和最小(HDU4311)
Meeting point-1 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- CSS禅意花园(设计一)
设计 1.排版样式. 正文部分文字比例比菜单不分班的大,可区分着两个区域(说明正文比菜单重要).排版也是一种交流方式,运用文字的大小.间距.颜色调整样式,给浏览者丰富的信息. 2.图标 3.分割线 适 ...
- 解决Xamarin 生成时出现 “aapt.exe”已退出,代码为 1。错误问题
项目中添加的资源或项目文件的名称不能包含 空格 横线 特殊符号 或者 Android关键字 等
- .NET: C#: 获取当前路径
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...
- linux下忘记mysql root密码解决办法
vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables [mysqld] skip-grant-tables :wq! #保存退出 s ...
- struts复合类型传值(对象传值)
01:导包,配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version ...
- sql 中的回车和换行问题
--移除回车符 update master_locationSET street_number = REPLACE(street_number, CHAR(13), '') --移除换行符 updat ...