直角三角形 纪中2543 枚举+hash
来源:互联网 发布:函数图像绘制软件 编辑:程序博客网 时间:2024/05/18 02:34
Description
平面上给定N个两两不同的整点,统计以给定的点为顶点,且直角边平行于坐标轴的直角三角形数。
Input
输入文件right.in第一行为一个整数N。
以下N行,每行给出一个点的坐标。
Output
输出文件名为right.out。输出一个整数表示统计结果。
分析
水题 先把每横线和每纵线上有多少个点都统计出来,然后枚举每一个点(坐标很大要用hash) 把这个点的横坐标的线和纵坐标的线上的点数分别-1后相乘 所有点的结果的和就是ans
const max2=100500; q=403219;var h,f,g:array[-5*max2..5*max2] of int64; h1,f1,g1:array[-5*max2..5*max2] of int64; x,y:array[1..max2] of longint; max,max1:longint; i,j,k:longint; ans:int64; n:longint;function hash(x:longint):longint;var i,j,k:longint;begin i:=x mod q; while (h[i]<>0) and (h[i]<>x) do i:=i mod q+1; hash:=i;end;function hash1(x:longint):longint;var i,j,k:longint;begin i:=x mod q; while (h1[i]<>0) and (h1[i]<>x) do i:=i mod q+1; hash1:=i;end;begin readln(n); max:=0; for i:=1 to n do begin readln(x[i],y[i]); j:=hash(y[i]); if h[j]<>y[i] then begin max:=max+1; f[j]:=max; h[j]:=y[i]; g[f[j]]:=g[f[j]]+1; end else g[f[j]]:=g[f[j]]+1; j:=hash1(x[i]); if h1[j]<>x[i] then begin max1:=max1+1; f1[j]:=max1; h1[j]:=x[i]; g1[f1[j]]:=g1[f1[j]]+1; end else g1[f1[j]]:=g1[f1[j]]+1; end; ans:=0; for i:=1 to n do begin ans:=ans+(g[f[hash(y[i])]]-1)*(g1[f1[hash1(x[i])]]-1); end; write(ans);end.
1 0
- 直角三角形 纪中2543 枚举+hash
- 直角三角形_纪中2543_暴力?
- 直角三角形 纪中 1385 数学_斜率
- 直角三角形 纪中 1385 数学_斜率 英文题解
- 直角三角形
- 直角三角形
- 直角三角形
- 直角三角形
- 直角三角形
- 直角三角形
- 直角三角形
- pku2769 枚举,hash
- POJ 2002 hash+枚举
- poj 1054 枚举+hash
- POJ 1840 Eqs(枚举+HASH)
- POJ2002-Squares-hash+枚举+几何
- [POJ 1840]Eqs[hash][枚举]
- HDU-4886(hash+暴力枚举)
- Android OnTouchEvent OnTouchListner 方法区别
- 基于MVP开发模式的简单Android项目
- vs2010对于读写锁技术的分离,很实用的c+新特性
- 关于web.xml里的filter的url-pattern配置问题
- android ScrollView嵌套listview的一些问题
- 直角三角形 纪中2543 枚举+hash
- xutils3框架之数据库使用详解!
- CTP源码分析4 CTP链路质量估计层结构及源码分析(三)----源码头文件解读
- 向量点乘相关公式推导及 几何解释
- TCP/IP、Http、Socket的区别
- linux常用脚本
- 接入京东开普勒报错: '+[UIImage imagePathCustomJDKeplerBundle:type:]: unrecognized selector sent to class
- 改变eclipse的快捷键
- configure: error: in `/usr/local/src/php-5.6.9':