hihocode——#1497 : Queen Attack
来源:互联网 发布:linux日志服务器配置 编辑:程序博客网 时间:2024/05/16 20:25
- 样例输入
5 1 1 2 2 3 3 1 33 1
样例输出
10
题意:给你很多皇后的坐标,问有多少对会互相攻击~~
思路:只要用4个map记录行列和两个斜边出现的次数就行~~
#include<bits/stdc++.h>using namespace std;map<int ,int > m1;map<int ,int > m2;map<int ,int > m3;map<int ,int > m4;typedef long long LL;int main(){ int n; LL ans=0; scanf("%d",&n); for(int i=0; i<n; i++) { int a,b; scanf("%d%d",&a,&b); ans+=m1[a]; m1[a]++; ans+=m2[b]; m2[b]++; ans+=m3[a+b]; m3[a+b]++; ans+=m4[b-a]; m4[b-a]++; } cout<<ans<<endl; return 0;}/*51 12 23 31 33 1*/
描述
There are N queens in an infinite chessboard. We say two queens may attack each other if they are in the same vertical line, horizontal line or diagonal line even if there are other queens sitting between them.
Now given the positions of the queens, find out how many pairs may attack each other?
输入
The first line contains an integer N.
Then N lines follow. Each line contains 2 integers Ri and Ci indicating there is a queen in the Ri-th row and Ci-th column.
No two queens share the same position.
For 80% of the data, 1 <= N <= 1000
For 100% of the data, 1 <= N <= 100000, 0 <= Ri, Ci <= 1000000000
输出
One integer, the number of pairs may attack each other.
- hihocode——#1497 : Queen Attack
- hihoCoder #1497 : Queen Attack
- hackerrank Queen's Attack II
- hihocode——#1498 : Diligent Robots
- 微软2017年预科生计划在线编程笔试第二场-#1497 : Queen Attack
- 【UVA11538】Chess Queen——简单组合
- UVA - 11538 —— Chess Queen
- Massive Attack——大规模进攻~~~~~~
- Queen
- hihoCode太阁最新面经算法6——扩展二进制数
- 【微软2017年预科生计划在线编程笔试第二场 A】Queen Attack
- Mary Queen of Scots——1、Fotheringhay
- Mary Queen of Scots——2、France
- Mary Queen of Scots——3、Darnley and Riccio
- Mary Queen of Scots——6、Kirk O'Field
- Mary Queen of Scots——7、Bothwell
- Mary Queen of Scots——8、England
- Mary Queen of Scots——9、A death
- LSM算法原理
- oracle TCL事务控制语言及 运算符
- 虚函数和纯虚函数
- 归并排序 小结
- 网易云课堂 Linux内核分析(七)
- hihocode——#1497 : Queen Attack
- Mac 10.11.6 Mysql
- 运维笔记40 Linux系统监控之Cacti(Cacti搭建,自动抓取cacti统计图片脚本)
- 数据结构—2207: 实现链表(线性表)
- C语言编程基础-struct和union
- HDP错误汇总
- spring中context:property-placeholder/元素
- FreeCodeCamp学习--Caesars Cipher
- 动态规划法(三)——最长公共子序列