codeforces 651C(map、去重)
来源:互联网 发布:帝国cms 附件绑定域名 编辑:程序博客网 时间:2024/06/05 08:35
题目链接: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;}
0 0
- codeforces 651C(map、去重)
- codeforces 651C. Watchmen(排列,去重)
- Codeforces--633D--Fibonacci-ish(暴力搜索+去重)(map)
- Codeforces--633D--Fibonacci-ish(map+去重)(twice)
- Codeforces 368B Sereja and Suffixes(map去重)
- List<Map>去重
- list<map<String ,object>> 去重,list map去重
- 用map实现去重
- map 遍历 ListBuffer去重
- map去重(不打乱存入顺序)
- 数组去重(c语言实现)
- c++vector去重
- Codeforces--670C--Cinema(STL map)
- List<Map<String,Object>>去重,排序
- List<Map<String,Object>>去重,排序
- List元素字符串放入Map去重
- 漏掉的账目(用C语言去重)
- C++:泛型编程set(排序去重)
- centos 5 6 7 在virtual box 和 vmware 里安装以后不能上外网的解决办法
- json与js对象的一些对比与区别
- java io系列12之 BufferedInputStream(缓冲输入流)的认知、源码和示例
- TCP MTU MSS
- 【hdu 3689】Infinite monkey theorem(概率dp+kmp)
- codeforces 651C(map、去重)
- 后缀树的学习(二)
- ARP欺骗原理
- servlet和cgi
- 习题8.11
- CentOS设置程序开机自启动的方法
- Maven的热部署
- unity3d--预设Prefab与实例Instantiate的基本使用
- 在js中使用正则表达式