题目:给你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的更多相关文章

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

  2. Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点

    Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...

  3. Codeforces Round #345 (Div. 1) A - Watchmen 容斥

    C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...

  4. Codeforces Round #345 (Div. 1) A. Watchmen (数学,map)

    题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数. 题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  7. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

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

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

随机推荐

  1. 日期和时间(datetime模块)

    前言: 参考:https://blog.csdn.net/weixin_42232219/article/details/89838580 在 python 中,datetime 是对日期数据进行处理 ...

  2. FFmpeg4.0笔记:VS2019编译FFmpeg4.0源码

    0.下载TDM.msys和yasm 1.安装TDM-GCC-64 2.安装msys到TDM-GCC的安装目录中 3.将call "C:\Program Files (x86)\Microso ...

  3. USB fuzzing

    简介 最近看一些USB fuzzing方面的东西,总结一下.主要是软件方面的工作. vUSBf 文章在这里:https://www.blackhat.com/docs/eu-14/materials/ ...

  4. JDK8~13新特性概览

    JDK8 1. 接口default 与 static 关键字 /** * jdk8中接口可以使用声明default和static修饰的方法 * static修饰的方法和普通的方法一样,可以被直接调用 ...

  5. IDEA导入Eclipse 非Maven的Web项目

  6. Python内置函数清单

    作者:Vamei 出处:http://www.cnblogs.com/vamei Python内置(built-in)函数随着python解释器的运行而创建.在Python的程序中,你可以随时调用这些 ...

  7. 仿造email后缀搜索功能(2)

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. JS实现table表格在鼠标移动出现一行变色或者十字叉变色

    1,一行变色 <script> function trBg(){ var tab=document.getElementById("table"); var tr=ta ...

  9. HashMap原理探究

    一.写随笔的原因:HashMap我们在平时都会用,一般面试题也都会问,借此篇文章分析下HashMap(基于JDK1.8)的源码. 二.具体的内容: 1.简介: HashMap在基于数组+链表来实现的, ...

  10. 【hdu 6089】Rikka with Terrorist

    题意 有一个 \(n\times m\) 的二维网格,其中有 \(k\) 个禁止点. 有 \(q\) 组询问,每组询问为给一个点,求有多少个矩形以这个点为一角且不包含禁止点. \(n,m,k,q\le ...