UVA - 10574 Counting Rectangles
Description
Problem H
Counting Rectangles
Input: Standard Input
Output:Standard Output
Time Limit: 3Seconds
Given n points on the XY plane, count how many regular rectanglesare formed. A rectangle is regular if and only if its sides are all parallel tothe axis.
Input
Thefirst line contains the number of tests
t(1<=t<=10).Each case contains a single line with a positive integer
n(1<=n<=5000),the number of points. There are
n lines follow, each line contains 2integers
x, y (0<=x, y<=109)indicating the coordinates of a point.
Output
Foreach test case, print the case number and a single integer, the number ofregular rectangles found.
SampleInput Output for Sample Input
2 5 0 0 2 0 0 2 2 2 1 1 3 0 0 0 30 0 900 |
Case 1: 1 Case 2: 0 |
题意:给定平面上的n个点,统计它们能组成多少个边平行于坐标轴的矩形
思路:题目要求平行于坐标轴,那么我们先找同一x轴的两个点组成的线段,保存两个点的y轴坐标,那么我们仅仅要再找两个端点在y轴平行的这样就能找到矩形了
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 5010; struct Point {
int x, y;
bool operator< (const Point &a) const {
if (x != a.x)
return x < a.x;
return y < a.y;
}
} p[maxn]; struct Edge {
int y1, y2;
Edge() {}
Edge(int y1, int y2) {
this->y1 = y1;
this->y2 = y2;
}
bool operator <(const Edge &a) const {
if (y1 != a.y1)
return y1 < a.y1;
return y2 < a.y2;
}
} e[maxn*maxn];
int n; int main() {
int t;
int cas = 1;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &p[i].x, &p[i].y);
sort(p, p+n);
int num = 0;
for (int i = 0; i < n; i++)
for (int j = i+1; j < n; j++) {
if (p[i].x != p[j].x)
break;
e[num++] = Edge(p[i].y, p[j].y);
}
sort(e, e+num);
int tmp = 1, ans = 0;
for (int i = 1; i < num; i++) {
if (e[i].y1 == e[i-1].y1 && e[i].y2 == e[i-1].y2)
tmp++;
else {
ans += tmp * (tmp-1) / 2;
tmp = 1;
}
}
ans += tmp * (tmp-1) / 2;
printf("Case %d: %d\n", cas++, ans);
}
return 0;
}
UVA - 10574 Counting Rectangles的更多相关文章
- UVA 10574 - Counting Rectangles(枚举+计数)
10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保 ...
- UVA 10574 - Counting Rectangles 计数
Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...
- Counting Rectangles
Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
- 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\) ...
- uva 1436 - Counting heaps(算)
题目链接:uva 1436 - Counting heaps 题目大意:给出一个树的形状,如今为这棵树标号,保证根节点的标号值比子节点的标号值大,问有多少种标号树. 解题思路:和村名排队的思路是一仅仅 ...
- UVA 12075 - Counting Triangles(容斥原理计数)
题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...
- [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)
Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...
随机推荐
- 【转】android 电容屏(三):驱动调试之驱动程序分析篇
关键词:android 电容屏 tp 工作队列 中断 坐点计算 电容屏主要参数平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:S5PV310( ...
- asp.net 错误处理
一.从客户端(...)中检测到有潜在危险的 Request.Form 值.(如图) 解决办法: 1.为 c:/windows/temp 文件夹 设置 IIS_Iusers 可读写权限 (可解决部分问题 ...
- Ajax跨域访问解决办法
方法1. jsonp实现ajax跨域访问示例 jsp代码: <body> <input type="button" onclick="testJsonp ...
- Android日语输入法Simeji使用示例
MainActivity如下: package cn.testsimeji; import android.os.Bundle; import android.view.View; import an ...
- COJ 1059 - Numeric Parity 位操作
非常好玩的一道题.能够熟悉下位操作实现和玩一玩bitset这个容器 Description We define the parity of an integer N as the sum of the ...
- Deppon接口开发
一.1) 支持的传输协议 http ,暂时只支持HTTP协议进行通信. (2) 支持的数据传输格式 Json ,所有接口暂只支持json消息格式. (3) 编码格式:UTF-8 交互编码格 ...
- ARCGIS接口详细说明
ArcGIS接口详细说明 目录 ArcGIS接口详细说明... 1 1. IField接口(esriGeoDatabase)... 2 2. IFieldEdit接口(esriGe ...
- android spinner 每行字体颜色都变化
final static int[] COLOR_LIST={Color.WHITE,Color.WHITE,Color.GRAY,Color.YELLOW,Color.RED}; spinner=( ...
- 在Yii框架中使用PHPExcel
PHPExcel是一个比较好用的php读取excel文件的类库,今天遇到了在yii中如何加载PHPExcel类文件的问题,因为Yii的autoload机制是安装类名去找文件,即文件名就是相应的类名,而 ...
- Android的动画
一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...