UVA - 10574 Counting Rectangles
来源:互联网 发布:中国网络什么时候墙的 编辑:程序博客网 时间:2024/04/30 17:08
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 integern(1<=n<=5000),the number of points. There aren 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
- uva 10574 - Counting Rectangles(计数)
- UVA 10574 - Counting Rectangles(枚举+计数)
- uva 10574 - Counting Rectangles (离散化)
- 10574 - Counting Rectangles
- Counting Rectangles
- [ZOJ1426 ][POJ1693] Counting Rectangles
- UVa10502 - Counting Rectangles
- poj 1693 Counting Rectangles
- EularProject 85:Counting rectangles
- UVA 11345 Rectangles
- UVa 460 - Overlapping Rectangles
- CodeForces 372B. Counting Rectangles is Fun
- Project Euler:Problem 85 Counting rectangles
- B. Counting Rectangles is Fun----dp
- Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun
- CF 372B Counting Rectangles is Fun(记忆化搜索)
- 如何在CSDN博客中编辑公式?
- USACO Section 1.3 PROB Calf Flac(最长回文子串)
- noncopyable
- 【算法导论学习-009】仅使用Random(0,1)实现Random(a,b)
- Java编程思想
- UVA - 10574 Counting Rectangles
- swift代码生成navigationController
- 8/10
- 基于Golang的分布式服务端开发日志(1)
- OC语法 子类与父类
- 时序图
- iOS_20_微博自定义可动画切换的导航控制器
- C++中 模板Template的使用 (typename)
- 南阳 477(浮点型的精度问题)