codeforces 651C(map、去重)
题目链接: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、去重)的更多相关文章
- CodeForces 651C Watchmen map
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
- 【CodeForces - 651C 】Watchmen(map)
Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...
- CodeForces - 651C Watchmen (去重)
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
- codeforces 651C Watchmen
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...
- Codeforces--633D--Fibonacci-ish (map+去重)(twice)
Fibonacci-ish Time Limit: 3000MS Memory Limit: 524288KB 64bit IO Format: %I64d & %I64u Su ...
- Map去重,去重value相同的元素,保留key最小的那个值
Map<Integer,String>,Integer代表时间撮,String代表文本信息去重函数:就是删除Map中value相同的元素,只保留key最小的那个元素 public stat ...
- codeforces 15D . Map 优先队列
题目链接 题目意思很简单nm的矩阵里, 选若干个ab的小矩阵, 定义每个矩阵的值为这个矩阵里的所有数的和-最小值*数的个数. 选小矩阵时, 优先选值最小的,然后次小的.. 知道不能选位置. 输出所有矩 ...
- List<Map>去重排序
数据格式 [ { "id":"d3e8a9d6-e4c6-4dd8-a94f-07733d3c1b59", "parentId":" ...
- Bacterial Melee CodeForces - 756D (dp去重)
大意: 给定字符串, 每次可以任选一个字符$x$, 将$x$左侧或右侧也改为$x$, 求最终能得到多少种字符串. 首先可以观察到最终字符串将连续相同字符合并后一定是原字符串的子序列 并且可以观察到相同 ...
随机推荐
- js 读取 地址栏参数 转
用JS获取地址栏参数的方法(超级简单) 方法一:采用正则表达式获取地址栏参数:( 强烈推荐,既实用又方便!) function GetQueryString(name) { var re ...
- css3放大效果
参考案例: http://www.web-designers.cn/ http://www.harmay.com/ 鼠标经过图片,图片放大. 1.html: <body> <div& ...
- java sqlhelper
dbinfo.properties部分: 注意每行末尾不可以有空格 #oracle configure UserName=scott Password=tiger Driver=oracle.jdbc ...
- [转]MYSQL高可用方案探究(总结)
前言 http://blog.chinaunix.net/uid-20639775-id-3337432.htmlLvs+Keepalived+Mysql单点写入主主同步高可用方案 http://bl ...
- Android中的内容提供器
用途 不同于File, SharedPreferences和DataBase,Content Provider主要用于不同的应用程序间共享数据,允许一个程序安全的访问另一个程序中的数据. 用法 通过C ...
- 悟javascript ---------------20160705
1. 首先观察页面需求 如果js要书写多个,那么一定用到循环 或者加上if判断 或者用到switch switch (表达式){ case 值1 : 语句1 break; case 值2 : 语句 ...
- dedecms qq咨询平均分配
qq后台页: qq_admin.php <style type="text/css"> <!-- * {margin:0; padding:0;} .wrap { ...
- c# UrlEncode,UrlDecode
用 C# winform 处理 utf-8,gb2312编码转换方法 首先,在项目属性 的 应用程序——目标框架中,选择 .NET Framework 4 然后再添加引用——.NET 中选择 ...
- Windows 10 RTM 官方正式版
Windows 10 各版本区别: Windows 10 家庭版:供家庭用户使用Windows 10 专业版:供小型企业使用 在家庭版基础上增加了域账号加入.bitlocker.企业商店等功能Wind ...
- UI数据库
一.数据库 SQL: SQL是Structured Query Language(结构化查询语言)的缩写.SQL是专为数据库而建立的操作命令集, 是一种功能齐全的数据库语言. 二.数据库管理系统 数据 ...