计算几何 点对处理 #345 (Div. 2) C. Watchmen
题目:给你n(<=2*1e5)个点,求其中有多少个点对之间的连线向量平行坐标轴;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int mod=100000000;
ll max(ll a,ll b)
{return a>b?a:b;};
int min(int a,int b)
{return a<b?a:b;}; struct node{
int x,y;
}ne[200005]; bool cmpx(node a,node b)
{
if(a.x==b.x) return a.y<b.y;
else return a.x<b.x;
} bool cmpy(node a,node b)
{
if(a.y==b.y) return a.x<b.x;
else return a.y<b.y;
} bool operator ==(const node &a,const node &b)
{
return a.x==b.x&&a.y==b.y;
} int main()
{
int n,m;
while(~scanf("%d",&m))
{
for(int i=0;i<m;i++) scanf("%d %d",&ne[i].x,&ne[i].y); ll ans=0;
sort(ne,ne+m,cmpx);
for(int i=0;i<m-1;i++)
{
int cur=i;
while(ne[i+1].x==ne[cur].x&&(i+1)<m) i++;
ll k=i-cur+1;ans+=(k-1)*k/2;//注意k要ll型,不然k*k的时候会爆int
}
sort(ne,ne+m,cmpy);
for(int i=0;i<m-1;i++)
{
int cur=i;
while(ne[i+1].y==ne[cur].y&&(i+1)<m) i++;
ll k=i-cur+1;ans+=(k-1)*k/2;
}
for(int i=0;i<m;i++)
{
int cur=i;
while(ne[i]==ne[i+1]&&(i+1)<m) i++;
ll k=i-cur+1;ans-=k*(k-1)/2;
}//去重操作
printf("%lld\n",ans);
}
return 0;
}
分析:刚开始只考虑到只有一个点的重合,用了unique果断错,,,后来发现只要x和y两个方向
枚举。然后再去重减去相同的点之间的就可以了
计算几何 点对处理 #345 (Div. 2) C. Watchmen的更多相关文章
- Codeforces Round #345 (Div. 1) A. Watchmen
A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点
Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...
- Codeforces Round #345 (Div. 1) A - Watchmen 容斥
C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...
- Codeforces Round #345 (Div. 1) A. Watchmen (数学,map)
题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数. 题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- Codeforces Round #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- codeforces Codeforces Round #345 (Div. 1) C. Table Compression 排序+并查集
C. Table Compression Little Petya is now fond of data compression algorithms. He has already studied ...
- Codeforces Round #345 (Div. 1) B. Image Preview
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed ...
随机推荐
- Hive 教程(七)-DML基础
DML,Hive Data Manipulation Language,数据操作语言: 通俗理解就是数据库里与数据的操作,如增删改查,统计汇总等: Loading files into tables ...
- oa_mvc_easyui_分页(4)
1.数据层的编写 NewListInfoDal.cs: GetPageEntityList方法,根据start,end取出数据 --row_number() over()函数查询 LoadEntity ...
- IDEA导入Eclipse 非Maven的Web项目
- 使用fiddler进程弱网测试
使用fiddler手机需调整所连网络代理模式为手动,主机名与端口改为与电脑相同 打开Fiddler,Rules(规则)->Performance(性能)->勾选 Simulate Mode ...
- 封装H5ToApp方法
方法一: 新建个 Android studio 项目,用 webview 指定访问你的页面 方法二: 使用工具 cordova 附上地址:http://cordova.axuer.com/docs/ ...
- JQuery——关于CDN(内容分发网络)
替代方案 如果您不希望下载并存放 jQuery,那么也可以通过 CDN(内容分发网络) 引用它. Staticfile CDN.百度.又拍云.新浪.谷歌和微软的服务器都存有 jQuery . 如果你的 ...
- abap 优化之ST05
DATA: gt_mara TYPE TABLE OF mara. SELECT * INTO TABLE gt_mara FROM mara WHERE MATKL = 'L000001' %_hi ...
- 多线程编程-- part 7 CountDownLatch
CountDownLatch简介 CountDownLatch是通过“共享锁”实现的.在创建CountDownLatch中时,会传递一个int类型参数count,该参数是“锁计数器”的初始状态,表示该 ...
- 18、nginx优化
一.性能优化概述 基询imm能优化,那么在性能优化这一章,我们将分为如下几个方面做介绍 1.首先我们需要了解性能优化要考虑哪些方面. 2.然后我们需要了解性能优化必须要用到的压力测试工具ab. 3.最 ...
- golang连接activemq,发送接收数据
介绍 使用golang连接activemq发送数据的话,需要使用一个叫做stomp的包,直接go get github.com/go-stomp/stomp即可 代码 生产者 package main ...