hihoCoder #1497 : Queen Attack
来源:互联网 发布:webview 加载js 阻塞 编辑:程序博客网 时间:2024/06/06 09:55
点击打开链接
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
- 样例输入
5 1 1 2 2 3 3 1 33 1
- 样例输出
10
描述
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.
#include<cstdio>#include<cstring>#include<iostream>#include<cmath>#include<cstdlib>#include<map>using namespace std;#define ll long longmap<int,int>m1;map<int,int>m2;map<int,int>m3;map<int,int>m4;int main(){ int n,a,b,ans=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d",&a,&b); ans+=m1[a]; m1[a]++; ans+=m2[b]; m2[b]++; ans+=m3[a+b]; m3[a+b]++; ans+=m4[a-b]; m4[a-b]++; } printf("%d\n",ans); return 0;}
阅读全文
0 0
- hihoCoder #1497 : Queen Attack
- hihocode——#1497 : Queen Attack
- hackerrank Queen's Attack II
- 微软2017年预科生计划在线编程笔试第二场-#1497 : Queen Attack
- Queen
- 【微软2017年预科生计划在线编程笔试第二场 A】Queen Attack
- Attack
- Attack
- hihocoder:
- hihoCoder
- Hihocoder
- hihocoder
- hihocoder
- hihocoder
- hihocoder
- hihocoder
- HihoCoder
- HihoCoder
- javascript运行过程中的“预编译阶段”和“执行阶段”
- arcgis api javascript 之GraphicsLayer图层的infoWindow消息窗实现
- Android proc目录
- 数组名的意义
- 移动端fixed和input获取焦点软键盘弹出影响定位的问题
- hihoCoder #1497 : Queen Attack
- 原生js模拟锚点,实现点击后,内容定位到本页的对应位置
- 3.购物车
- 人人网2011前端工程师笔试卷
- HDOJ1257 最少拦截系统(DP,LIS模板,low_bound)
- 低功耗项目小小心得
- 文件上传下载之commons-fileupload
- 《深入理解Java虚拟机》第7章 虚拟机类加载机制
- linux 默认系统语言修改