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轴上的点相等就是一种,  对于一堆相等的 我们用组合数就好了

  1. //meek
  2. ///#include<bits/stdc++.h>
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <cmath>
  6. #include <string>
  7. #include <cstring>
  8. #include <algorithm>
  9. using namespace std ;
  10. typedef long long ll;
  11. #define mem(a) memset(a,0,sizeof(a))
  12. #define pb push_back
  13. #define fi first
  14. #define se second
  15. #define MP make_pair
  16.  
  17. const int N=;
  18. const ll INF = 1ll<<;
  19. const int inf = <<;
  20. const int mod= ;
  21. const int M = ;
  22.  
  23. struct ss{
  24. int x,y;
  25. }a[N],p[N*N];
  26. int cnt;
  27. int cmp(ss s1,ss s2) {
  28. if(s1.x == s2.x) return s1.y<s2.y;
  29. return s1.x<s2.x;
  30. }
  31. void init() {
  32. cnt = ;mem(p);
  33. }
  34. ll solve() {
  35. ll ans = ;
  36. for(int i = ;i < cnt; ) {
  37. int now = i+;
  38. while(p[i].x == p[now].x && p[i].y == p[now].y) now++;
  39. ll c = now - i;
  40. if(c>=) ans += c*(c-)/;
  41. i = now;
  42. }
  43. return ans;
  44. }
  45. int main() {
  46. int T,n,x,y,cas = ;
  47. scanf("%d",&T);
  48. while(T--) {
  49. init();
  50. scanf("%d",&n);
  51. for(int i=;i<=n;i++) {
  52. scanf("%d%d",&x,&y);
  53. a[i].x = x;
  54. a[i].y = y;
  55. }
  56. sort(a+,a+n+,cmp);
  57. cnt = ;
  58. for(int i=;i<=n;i++) {
  59. for(int j=i+;j<=n;j++) {
  60. if(a[i].x != a[j].x) {
  61. break;
  62. }
  63. p[cnt].x = a[i].y;
  64. p[cnt].y = a[j].y;
  65. cnt++;
  66. }
  67. }
  68. printf("Case %d: ",cas++);
  69. sort(p,p+cnt,cmp);
  70. printf("%lld\n",solve());
  71. }
  72. return ;
  73. }

代码

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. 打造一款属于自己的web服务器——开篇

    JVM总结慢慢来吧,先插播一篇水文,来介绍下最近业余一直在写的一个小项目——easy-httpserver(github).适合新手学习,大神们路过即可^_^. 一.这是个什么玩意? easy-htt ...

  2. 条款24:若所有的函数参数可能都需要发生类型转换才能使用,请采用non-member函数

    假设有一个有理数类Rational,有一个计算有理数乘法的成员函数operator*,示例如下: #include <iostream> class Rational { public: ...

  3. LoadRunner - 当DiscuzNT遇上了Loadrunner(下) (转发)

    当DiscuzNT遇上了Loadrunner(下) 在之前的两篇文章中,基本上介绍了如何录制脚本和生成并发用户,同时还对测试报告中的几个图表做了简单的说明.今天这篇文章做为这个系列的最后一篇,将会介绍 ...

  4. 57.DDR3的系统时钟编译错误

    错误:Xst:2033 - Port I of Input buffer ddr3_mig/memc3_infrastructure_inst/se_input_clk.u_ibufg_sys_clk ...

  5. 零基础学习Linux(一)环境搭建

    从本文开始我会为大家介绍一下linux环境下详细的集群环境安装.配置.部署到实例演示的整个过程.在此过程中会给大家详细介绍一下Linux的操作技巧和一些工具的使用.今天开始第一步——环境搭建. 第一步 ...

  6. iOS9新系统下APP Store 应用上传新指南

    一 iTunes Connect介绍 iTunes Connect是面向iOS应用开发人员的苹果门户网站,供开发人员管理其应用,跟踪下载情况.今年1月份闹得沸沸扬扬的iTunes Connect BU ...

  7. TI IPNC Web网页之流程分析

    流程 Appro IPNC使用的web服务器是boa. 请仔细理解下面这段话. boa这个web服务器是GUI界面和IPNC应用程序之间的通信的桥梁.它的责任是从web GUI中接收HTTP请求,并且 ...

  8. apache-commons-net Ftp 进行文件、文件夹的上传下载及日志的输出

    用到了apache 的 commons-net-3.0.1.jar 和 log4j-1.2.15.jar 这连个jar包 JAVA 代码如下: package com.bjut.edu.cn.ftp; ...

  9. 项目中添加Log4J支持

    首先,在项目中的classes 中新建立一个log4j.properties文件即可: 在实际编程时,要使Log4j真正在系统中运行事先还要对配置文件进行定义.定义步骤就是对Logger.Append ...

  10. Netsharp快速入门(之14) 销售管理(报表A 热销滞销品统计)

    作者:秋时 杨昶   转载须说明出处 4.5     销售报表 4.5.1  热销滞销品统计 1.建立部件工作区,主部件选择报表.统计表,辅部件选择查询方案 2.设置报表模版.选择主部件,选择工具-报 ...