Codeforces Round 345 (Div. 1)A. Watchmen(容斥原理)
A. Watchmen
当欧几里得距离和曼哈顿距离相等时,\(x1==x2||y1==y2\)
这两个条件满足其一。这和容斥原理一样,至少选择一个的条件。
我们可以计算xi,以及小于i之前的这些,这样可以保证只计算一次。
然后容斥一下计算答案。
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
void solve()
{
int n;cin>>n;
map<int,int>cntx,cnty;
map<pii,int>s;
int ans=0,k=0;
rep(i,1,n){
int x,y;cin>>x>>y;
ans+=cntx[x]+cnty[y]-s[{x,y}];
cntx[x]++;
cnty[y]++;
s[{x,y}]++;
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
// cin>>_;
// while(_--)
solve();
return 0;
}
Codeforces Round 345 (Div. 1)A. Watchmen(容斥原理)的更多相关文章
- 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 ...
- Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点
Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...
- Codeforces Round #345 (Div. 1) A - Watchmen 容斥
C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...
- Codeforces Round #345 (Div. 1) A. Watchmen (数学,map)
题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数. 题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...
- Codeforces Round #345 (Div. 2) C (multiset+pair )
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集
E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...
随机推荐
- iframe 框架技术
隐性转发 <!doctype html> <html lang="zh_CN"> <head> <meta charset="u ...
- 【Java】ArrayList线程不安全的坑
问题复现: 使用Java的steam().paralleStream(),foreach()方法向ArrayList添加数据,导致ArrayList中出现空值,代码如下: public static ...
- python入门之后须掌握的知识点(excel文件处理+邮件发送+实战:批量化发工资条)【二】
相关文章: python处理Excel实现自动化办公教学(含实战)[一] python处理Excel实现自动化办公教学(含实战)[二] python处理Excel实现自动化办公教学(数据筛选.公式操作 ...
- 【C++深度剖析】为什么C++支持函数重载而C不支持--C++程序编译链接过程--符号表生成规则【Linux环境超详细解释C++函数重载底层原理】
文章目录 前言 Linux环境g++编译器的配置以及一些准备工作 源文件的符号表生成以及分析 尾声 前言 先赞后看好习惯 打字不容易,这都是很用心做的,希望得到支持你 大家的点赞和支持对于我来说是一种 ...
- 配置PHP的运行环境
一.wamp Wamp是Windows Apache Mysql PHP的缩写,即在windows下将Apache+PHP+Mysql集成的开发环境,操作简单一键安装,摆脱手动修改配置文件的繁琐. 图 ...
- .NET Core开发实战(第24课:文件提供程序:让你可以将文件放在任何地方)--学习笔记
24 | 文件提供程序:让你可以将文件放在任何地方 文件提供程序核心类型: 1.IFileProvider 2.IFileInfo 3.IDirectoryContents IFileProvider ...
- MySQL8.0-CTE递归查询(避免死循环)
TSQL脚本能实现递归查询,用户使用共用表表达式 CTE(Common Table Expression),只需要编写少量的代码,就能实现递归查询. 本文详细介绍CTE递归调用的特性和使用示例,递归查 ...
- Blazor OIDC 单点登录授权实例5 - 独立SSR App (net8 webapp ) 端授权
目录: OpenID 与 OAuth2 基础知识 Blazor wasm Google 登录 Blazor wasm Gitee 码云登录 Blazor OIDC 单点登录授权实例1-建立和配置IDS ...
- 顺着这份Java面试地图,国内一二线互联网公司随便进...
原创:陶朱公Boy(微信公众号ID:taozhugongboy),欢迎分享,转载请保留出处. 前言 临近春节,这几天手头没什么事情,花了点时间,将自己近两年收集的面试真题,进行了一番深度归纳总结,整理 ...
- 【开工大吉】推荐4款开源、美观的WPF UI组件库
前言 经常有小伙伴在技术群里提问:WPF有什么好用的UI组件库?,今天大姚给大家推荐4款开源.美观的WPF UI组件库. WPF介绍 WPF 是一个强大的桌面应用程序框架,用于构建具有丰富用户界面的 ...