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 计数的更多相关文章

  1. UVA 10574 - Counting Rectangles(枚举+计数)

    10574 - Counting Rectangles 题目链接 题意:给定一些点,求可以成几个边平行于坐标轴的矩形 思路:先把点按x排序,再按y排序.然后用O(n^2)的方法找出每条垂直x轴的边,保 ...

  2. UVA - 10574 Counting Rectangles

    Description Problem H Counting Rectangles Input: Standard Input Output:Standard Output Time Limit: 3 ...

  3. Counting Rectangles

    Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...

  4. counting sort 计数排序

    //counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorit ...

  5. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  6. 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 ...

  7. Codeforces 372 B. Counting Rectangles is Fun

    $ >Codeforces \space 372 B.  Counting Rectangles is Fun<$ 题目大意 : 给出一个 \(n \times m\) 的 \(01\) ...

  8. uva 1436 - Counting heaps(算)

    题目链接:uva 1436 - Counting heaps 题目大意:给出一个树的形状,如今为这棵树标号,保证根节点的标号值比子节点的标号值大,问有多少种标号树. 解题思路:和村名排队的思路是一仅仅 ...

  9. UVA 12075 - Counting Triangles(容斥原理计数)

    题目链接:12075 - Counting Triangles 题意:求n * m矩形内,最多能组成几个三角形 这题和UVA 1393类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...

随机推荐

  1. UIAlertController——之Block回调

    iOS8.0之后出现的提示框 =.=,比自己去改block回调要好.

  2. SqlParameter[] 添加

    protected void Button1_Click(object sender, EventArgs e) { string strSql="insert into Invoice_R ...

  3. Matlab实现加性高斯白噪声信道(AWGN)下的digital调制格式识别分类

    Matlab实现加性高斯白噪声信道(AWGN)下的digital调制格式识别分类 内容大纲 加性高斯白噪声信道(AWGN)下的digital调制格式识别分类 (1. PSK; 2. QPSK; 3.8 ...

  4. 28335 sci fifo send

    #include "DSP2833x_Device.h"#include "DSP2833x_Examples.h"char buf[]={0x30,0x32, ...

  5. SQLite数据库的基本API函数

    1 .打开数据库: 说明:打开一个数据库,文件名不一定要存在,如果此文件不存在, sqlite 会自动创建.第一个参数指文件名,第二个参数则是定义的 sqlite3 ** 结构体指针(关键数据结构), ...

  6. 通过HTML5实现发送声音

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  7. Visual Studio 2013 各版本注册码

    Visual Studio Ultimate 2013 KEY(密钥):BWG7X-J98B3-W34RT-33B3R-JVYW9 Visual Studio Premium 2013 KEY(密钥) ...

  8. 【CentOS】Eclipse插件egit使用

    1.简介 2.安装 3.配置 4.使用 5.补充说明   参考资料: http://yufenfei.iteye.com/blog/1750124    1.简介     EGit就是一款Eclips ...

  9. 剑指offer--面试题22

    关键在于思路,  需要两个输入向量,而函数中需要一个辅助栈! 思路:以待判出栈序列为基础,逐个判断它与栈顶元素是否相等,相等则弹出且j++,这表明此元素可为出栈顺序元素,不相等则栈元素不断入栈,直至相 ...

  10. 12 高性能I/O框架库Libevent

    这里不讲Libevent库的具体内容了,从宏观上对I/O库整体做个介绍 Linux服务器程序必须处理三类事件:I/O事件,信号和定时事件 统一事件源:统一处理这三类事件既能使代码简单易懂,又能避免一些 ...