题目链接: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. biweb后台添加上传下载功能

    1.数据库对应表添加字段 file       varchar(100) 2.对应的后台 模块名/admin/addinfo.php里添加如下代码: //文件上传 if ((($_FILES[&quo ...

  2. 如何让一个json文件显示在表格里

    <body> //首先得把架子搭起来 <table id = "tb" border="1"> <tr></tr> ...

  3. c#判断IP是否可以Ping通

    Ping pingSender = new Ping(); PingReply reply = pingSender.Send("127.0.0.1",120);//第一个参数为i ...

  4. JavaEE Spring

    1.  Spring以一己之力撼动了Sun公司的JavaEE传统重量级框架(EJB),逐渐成为使用最多的JavaEE企业应用开发框架. 2.  Spring是分层的JavaEE应用一站式的轻量级开源框 ...

  5. java动手动脑和课后实验型问题String类型

    1.请运行以下示例代码StringPool.java,查看其输出结果.如何解释这样的输出结果?从中你能总结出什么? true true false 总结: 使用new关键字创建字符串对象时, 每次申请 ...

  6. Flapper Bird的学习笔记(三)

    因为我有一个超屌的梦想,所以就绝不会做一个孬种的追梦人! 完成音效的添加 单例模式 游戏的状态切换 1. 单例模式 首先呢,说一下单例模式.何为单例?单例模式是一种常用的软件设计模式.在它的核心结构中 ...

  7. Spring Security (一)

    一.pom.xml <!-- spring security --> <dependency> <groupId>org.springframework.secur ...

  8. mysql的卸载方法

    sudo rm /var/lib/mysql/ -R 删除mysql的数据文件 2 sudo rm /etc/mysql/ -R 删除mqsql的配置文件 3 sudo apt-get autorem ...

  9. C#机器视觉入门系列1-转化为灰度图&&3*3模糊

    这是我入门机器视觉的系列学习经验之开篇,本来想着依靠opencv快速实现一些功能,但是想了一下既然是学数学的,还是应该自己多算算,写一些自己理解的东西才好. 入门篇很简单,就只是实现了转化成灰度图以及 ...

  10. as3 中文转拼音

    private static const PinYin:Object = {"a":"\u554a\u963f\u9515","ai":&q ...