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类似,把总情况扣去三点共线情况,那么问题转化为求三点共线的情况,对 ...
随机推荐
- ios中怎么样判断路径最后的后缀名称
使用hasSuffix属性即可 例如 [photo.thumbnail_pic.lowercaseString hasSuffix:@"gif"]
- Java之蛋疼的file Protocol
file Protocol Opens a file on a local or network drive. Syntax file:///sDrives[|sFile] Tokens sDrive ...
- netlink+netfilter
http://blog.chinaunix.net/uid-21768364-id-3618377.html
- linux安装R语言
系统:centos 6.4 64bit 安装可以使用rpm包安装,也可以用源码安装. 但是rpm安装,各种依赖比较麻烦.所以我采用源码安装. 下载:http://www.r-project.org/ ...
- iOS进阶学习-CoreData
一.CoreData数据库框架的优势 1.CoreData数据持久化框架是Cocoa API的一部分,首次在iOS5版本的系统中出现,它允许按照实体-属性-值模型组织数据,并以XML.二进制文件或者S ...
- 加速传感器(CoreMotion) swift
// // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...
- sqlite与C++进行连接
SQLite数据库是零配置的,sqlite数据库不同于SqlServer等数据库,SQLite不需要复杂配置,只需要,将SQLite的库文件和动态链接文件拷贝到相应工程目录下,就可以使用SQLite数 ...
- 网络笔记02数据解析 -1-JSON解析
1.JSON解析 1.JSON介绍 JSON是最网络传输数据最为广泛的数据格式,没有之一,出身草根,是Javascript的子集,专门负责描述数据格式.Javascript是网页开发的一种脚本语言,和 ...
- “我爱淘”冲刺阶段Scrum站立会议2
完成任务: 已经将菜单栏和首页精选页面整合在一起了,现在正在做第二个界面--分类. 计划任务: 将分类页面制作完毕,并可以整合到整体里,可以进行菜单点击的切换. 遇到问题: 1.分类页面布局的制作不好 ...
- ASP.NET本质论阅读----线程与异步
线程 概要:操作系统通过线程对程序的执行进行管理 线程的数据结构:1.线程的核心对象(包含线程的当前寄存器状态),调用线程时-寄存器状态被加载到CPU中. 2.线程环境块TEB:一块用户模式下的内存 ...