题目链接:http://codeforces.com/contest/651/problem/C

思路:结果就是计算同一横坐标、纵坐标上有多少点,再减去可能重复的数量(用map,pair存一下就OK了)。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
const int N = 2e5 + 5;
map <int,int> x,y;
map <pii,int> s;
map <int,int> :: iterator it1;
map <pii,int> :: iterator it2;
int main()
{
int n;
scanf("%d",&n);
ll ans = 0;
for(int i = 1; i <= n; i++)
{
int a,b;
scanf("%d %d",&a,&b);
x[a]++,y[b]++;
s[pii(a,b)]++;
}
for(it1 = x.begin(); it1 != x.end(); it1++)
ans += (ll)(it1->second)*(it1->second - 1) >> 1;
for(it1 = y.begin(); it1 != y.end(); it1++)
ans += (ll)(it1->second)*(it1->second - 1) >> 1;
for(it2 = s.begin(); it2 != s.end(); it2++)
ans -= (ll)(it2->second)*(it2->second - 1) >> 1;
printf("%I64d\n",ans);
return 0;
}

codeforces 651C(map、去重)的更多相关文章

  1. CodeForces 651C Watchmen map

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  2. 【CodeForces - 651C 】Watchmen(map)

    Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...

  3. CodeForces - 651C Watchmen (去重)

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  4. codeforces 651C Watchmen

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  5. Codeforces--633D--Fibonacci-ish (map+去重)(twice)

     Fibonacci-ish Time Limit: 3000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u Su ...

  6. Map去重,去重value相同的元素,保留key最小的那个值

    Map<Integer,String>,Integer代表时间撮,String代表文本信息去重函数:就是删除Map中value相同的元素,只保留key最小的那个元素 public stat ...

  7. codeforces 15D . Map 优先队列

    题目链接 题目意思很简单nm的矩阵里, 选若干个ab的小矩阵, 定义每个矩阵的值为这个矩阵里的所有数的和-最小值*数的个数. 选小矩阵时, 优先选值最小的,然后次小的.. 知道不能选位置. 输出所有矩 ...

  8. List<Map>去重排序

    数据格式 [ { "id":"d3e8a9d6-e4c6-4dd8-a94f-07733d3c1b59", "parentId":" ...

  9. Bacterial Melee CodeForces - 756D (dp去重)

    大意: 给定字符串, 每次可以任选一个字符$x$, 将$x$左侧或右侧也改为$x$, 求最终能得到多少种字符串. 首先可以观察到最终字符串将连续相同字符合并后一定是原字符串的子序列 并且可以观察到相同 ...

随机推荐

  1. Python:dict用法

    dict全称dictionary,使用键-值(key-value)存储,有极快的查找速度. 以下整理几种常用的dict用法 定义 空dict >>> dict={} 普通dict & ...

  2. mongodb-索引

    说明:创建索引时,列名:int 中的int数字指的是正序或者倒序,如果是1表明是正序,-1表示倒序 1.查询collection上的索引 db.users.getIndexes() 2.查询当前的db ...

  3. 浅谈学习掌握linux系统的优势

    Linux系统让我们懂得了共享.开放.自由可以让人类生活的更加美好,开源精神是一种让每个从事Linux行业的技术人员从骨子里自豪的情怀,开源产品的兴盛受益于开源社区的强壮根基.Linux真的给了我很多 ...

  4. codeforces 727F. Polycarp's problems

    题目链接:http://codeforces.com/contest/727/problem/F 题目大意:有n个问题,每个问题有一个价值ai,一开始的心情值为q,每当读到一个问题时,心情值将会加上该 ...

  5. jquery 单击和双击事件冲突解决方案

    先看一下点击事件的执行顺序: 单击(click):mousedown,mouseout,click: 双击(dblclick):mousedown,mouseout,click , mousedown ...

  6. sql 删除数据库所有用户表

    --变量@tablename保存表名 declare @tablename nvarchar() --将用户表全部保存到临时表#tablename中 SELECT [name] into #table ...

  7. android 打包失败

    如果在打包时提示: proguard returned with error code 1   并且在控制台中输出:'java'不是内部或外部程序或批处理文件 那么就说明你的环境变量出问题了,之前用的 ...

  8. Visro 应用的前端模板工具介绍 -JsRender

    1.什么是JsRender: JsRender是一款JavaScript模版引擎,是具有简单直观,功能强大,可扩展的,早期版本是基于JQUERY 写的,后来作者重构了,就不再依赖JQUERY了. 它的 ...

  9. Web开发中最致命的8个小错误

    错误1:表单的label标签跟表单字段没有关联 利用“for”属性允许用户单击label也可以选中表单中的内容.这可以扩大复选框和单选框的点击区域,非常实用. 错误2:logo图片没有链接到主页 点击 ...

  10. rocksDB 安装问题简单介绍

    前一段时间准备测试rocksdb,按照帖子和官网的例子,在安装过程中遇到一些问题.这里给出的是在Ubuntu下安装python使用的版本. 首先,要感谢这些帖子对我的帮助: 1:http://tech ...