UVA 10574 - Counting Rectangles 计数
Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular if and only if its sides are all parallel to the axis.
Input
The first 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 2
integers x, y (≤ x, y ≤ 109
) indicating the coordinates of a point.
Output
For each test case, print the case number and a single integer, the number of regular rectangles found.
Sample Input
2
5
0 0
2 0
0 2
2 2
1 1
3
0 0
0 30
0 900
Sample Output
Case 1: 1
Case 2: 0
题意:给你n个点 ,问你这些点能够组成多少个 长宽和坐标轴平行的 矩形
题解:按照x排序,在y轴平行下,选择不同直线组合,满足两y轴上的点相等就是一种, 对于一堆相等的 我们用组合数就好了
//meek
///#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair const int N=;
const ll INF = 1ll<<;
const int inf = <<;
const int mod= ;
const int M = ; struct ss{
int x,y;
}a[N],p[N*N];
int cnt;
int cmp(ss s1,ss s2) {
if(s1.x == s2.x) return s1.y<s2.y;
return s1.x<s2.x;
}
void init() {
cnt = ;mem(p);
}
ll solve() {
ll ans = ;
for(int i = ;i < cnt; ) {
int now = i+;
while(p[i].x == p[now].x && p[i].y == p[now].y) now++;
ll c = now - i;
if(c>=) ans += c*(c-)/;
i = now;
}
return ans;
}
int main() {
int T,n,x,y,cas = ;
scanf("%d",&T);
while(T--) {
init();
scanf("%d",&n);
for(int i=;i<=n;i++) {
scanf("%d%d",&x,&y);
a[i].x = x;
a[i].y = y;
}
sort(a+,a+n+,cmp);
cnt = ;
for(int i=;i<=n;i++) {
for(int j=i+;j<=n;j++) {
if(a[i].x != a[j].x) {
break;
}
p[cnt].x = a[i].y;
p[cnt].y = a[j].y;
cnt++;
}
}
printf("Case %d: ",cas++);
sort(p,p+cnt,cmp);
printf("%lld\n",solve());
}
return ;
}
代码
UVA 10574 - Counting Rectangles 计数的更多相关文章
- UVA 10574 - Counting Rectangles(枚举+计数)
10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保 ...
- UVA - 10574 Counting Rectangles
Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...
- Counting Rectangles
Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...
- counting sort 计数排序
//counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorit ...
- 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类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...
随机推荐
- AOP在 .NET中的七种实现方法
7Approaches for AOP in .Net AOP在 .NET中的七种实现方法 Here are all the ways that I can think of to add AOPto ...
- python实现树莓派生成并识别二维码
python实现树莓派生成并识别二维码 参考来源:http://blog.csdn.net/Burgess_Liu/article/details/40397803 设备及环境 树莓派2代 官方系统R ...
- qt 焦点设置策略
focusPolicy 一个QWidget获得焦点的方式受 focusPolicy 控制 Qt::TabFocus 通过Tab键获得焦点 Qt::ClickFocus 通过被单击获得焦点 Qt::St ...
- [shell基础]——awk命令
关于awk awk是一个强大的文本分析工具,相对于grep的查找.sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大. 简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开 ...
- android开发实现静默安装(fota升级)
这里只提供一个思路,也是咨询大神才了解到的. fota升级主要用于系统及系统应用的升级,不过貌似也会弹出提示用于用户确认.既然做到系统级别了,估计也一样可以静默安装的.
- 【Minimum Depth of Binary Tree】cpp
题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...
- 【Convert Sorted List to Binary Search Tree】cpp
题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height ...
- window8左下角窗口和右上角窗口失效解决方法
win8系统有时会出现任务栏和桌面点击没反应 小常识: “Windows徽标键” 这个键,左右各一个,称为“Windows徽标键”,键冒上的图案为Windows徽标,由此得名. [知识链接]位于计算机 ...
- 单点登陆CAS安装过程中可能遇到的问题
可能遇到的问题: 错误: java.security.cert.CertificateException: No name matching localhost found 原因: keystore里 ...
- SSRF攻击实例解析
ssrf攻击概述 很多web应用都提供了从其他的服务器上获取数据的功能.使用用户指定的URL,web应用可以获取图片,下载文件,读取文件内容等.这个功能如果被恶意使用,可以利用存在缺陷的web应用作为 ...