CF621B - Wet Shark and Bishops
来源:互联网 发布:javbus新域名2017 编辑:程序博客网 时间:2024/06/10 05:15
题目大意:在一个1000*1000的国际象棋棋盘上,有n个“相”,只要在同一条对角线上的相就能互相攻击,不管中间有没有别的相,求可以互相攻击的相的对数。
互相攻击的相满足的条件有两个,坐标x+y相等或者x-y相等。所以可以按照x+y和x-y为关键字分别排两次序,相同关键字的q个相可以组成(1+q-1)*(q-1)/2对,计算即可。
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<algorithm>#include<cmath>using namespace std;struct xiang{int x,y;bool friend operator<(xiang a,xiang b){return a.x-a.y<b.x-b.y;}}a[220000];struct xiang2{int x,y;bool friend operator<(xiang2 a,xiang2 b){return a.x+a.y<b.x+b.y;}}b[220000];int n;int main(){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);memcpy(b,a,sizeof(b));long long ans=0;sort(a+1,a+1+n);int ji=0;a[0].y=2000;for(int i=1;i<=n;i++){if(a[i].x-a[i].y==a[i-1].x-a[i-1].y){ji++;}else{ji=1;}ans+=(long long)(ji-1);}sort(b+1,b+1+n);ji=0;b[0].y=-2000;for(int i=1;i<=n;i++){if(b[i].x+b[i].y==b[i-1].x+b[i-1].y){ji++;}else{ji=1;}ans+=(long long)(ji-1);}cout<<ans<<endl;return 0;}
0 0
- CF621B - Wet Shark and Bishops
- Wet Shark and Bishops
- Wet Shark and Bishops
- Wet Shark and Bishops
- Codeforces Round #341 (Div. 2) CF621B. Wet Shark and Bishops(排列组合+对角线规律)
- codeforces621B. Wet Shark and Bishops
- B. Wet Shark and Bishops
- (思维)Wet Shark and Bishops
- codeforce 621B Wet Shark and Bishops
- codeforce 621 B. Wet Shark and Bishops
- CodeForces 621 B Wet Shark and Bishops
- 【codeforces】#621B-Wet Shark and Bishops
- 【CodeForces】[621B]Wet Shark and Bishops
- 【CodeForces】#621B - Wet Shark and Bishops
- CodeForces 621B Wet Shark and Bishops
- CodeForces 621B Wet Shark and Bishops
- Codeforces 621B Wet Shark and Bishops
- Wet Shark and Bishops(思维)
- 刷新与删除思路
- 设计模式之适配器模式
- CF621A - Wet Shark and Odd and Even
- Start
- unity android 接入admob
- CF621B - Wet Shark and Bishops
- IP
- openGL代码入门笔记[2]:绘制直线、圆以及椭圆
- CF621C - Wet Shark and Flowers
- mybatis开发规范
- 传智播客168期JavaEE就业班(第四天 dom)
- pentest - masscan-web-ui
- Algorithms(week 1,普林斯顿大学公开课)
- CF621D - Rat Kwesh and Cheese