计算几何 点对处理 #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 ...
随机推荐
- [转帖]CentOS 7安装并启动Google浏览器(★firecat亲测有效★)
CentOS 7安装并启动Google浏览器(★firecat亲测有效★) https://blog.csdn.net/libaineu2004/article/details/82821405 自己 ...
- 阿里云服务器挖矿脚本bioset攻击解决
1.问题出现 一大早刚起床,阿里云就给我发了一条短信,提醒我服务器出现紧急安全事件:挖矿程序 阿里云“贴心”地提供了解决方法,不过需要购买企业版的安全服务,本着能自己动手就不花钱原则自己搞了起来 于是 ...
- POJ - 1815 Friendship (最小点割集)
(点击此处查看原题) 题目分析 题意:有n个人,编号记为1~n,n个人之间可能有人可以互相联系,如果A能和B联系,那么至少满足这两种情况之一:(1)A知道B的电话(2)A可以和C联系,并且C可以和B联 ...
- 移动端、pc端通用点击复制
点击复制 function copyArticle(event){ const range = document.createRange(); range.selectNode(document.ge ...
- 滚动页面产生动画WOW.js的用法
简介 在一些网页上,当你滚动页面的时候会看到各式各样的元素动画效果,非常动感.WOW.js 就是一款帮助你实现这种 CSS 动画效果的插件.WOW.js 依赖 animate.css,所以它支持 an ...
- LoadRunner之使用JSEESIONID访问网站
LoadRunner使用笔记 JSESSIONID的含义:https://www.cnblogs.com/caiwenjing/p/8081391.html 1.使用JSESSIONID访问网站 Ac ...
- 转载Spring Data JPA 指南——整理自官方参考文档
转载:https://blog.csdn.net/u014633852/article/details/52607346 官方文档 https://docs.spring.io/spring-data ...
- Hadoop单节点启动分布式伪集群
emm~ 写这篇博客只是手痒,因为开发环境用单节点就够了,生产环境肯定是真实集群,所以这个伪分布式纯属娱乐而已. 配置HDFS1. 安装好一台hadoop,可以参考这篇博客.2. 在hadoop目录下 ...
- Windows2003服务器IIS启用Gzip压缩的设置
http://jingyan.baidu.com/article/148a192178ec834d71c3b12b.html 步骤 1 2 3 本文介绍的HTTP压缩方式,采用的是Window ...
- Zookeeper VS Chubby
目录 区别的根源 1)一致性 2)Client Cache vs No Cache 总结 参考资料 区别的根源 一个设计良好的系统应该是围绕并为其设计目标服务的. Chubby:p ...