2543. 【NOIP2011模拟9.1】直角三角形 (StandardIO)
来源:互联网 发布:wto数据库 编辑:程序博客网 时间:2024/05/16 10:21
2543. 【NOIP2011模拟9.1】直角三角形 (StandardIO)
Description
平面上给定N个两两不同的整点,统计以给定的点为顶点,且直角边平行于坐标轴的直角三角形数。
Input
输入文件right.in第一行为一个整数N。
以下N行,每行给出一个点的坐标。
Output
输出文件名为right.out。输出一个整数表示统计结果。
Sample Input
4
0 0
0 1
1 0
1 1
Sample Output
4
Hint
【数据规模和约定】
30%的数据满足 N ≤ 100;
50%的数据满足 N ≤ 1000;
100%的数据满足0 < N ≤ 100000,所有坐标不超过32位整数范围。
思路:
找出每一个对于同一个点行和列相同的个数,然后相乘就可以了。然后全部加起来。
用哈气或二分优化都可以
程序:
const maxn=1000007;var a,b,a1,b1,x,y:array [0..maxn] of longint; i,j,n,q,p:longint; ans:int64;procedure add(x:longint);var i,j:longint;begin i:=xmod maxn; while(a1[i]<>0)and (a[i]<>x) and (i<maxn) do inc(i); a[i]:=x; inc(a1[i]);end; procedure add1(x:longint);var i,j:longint;begin i:=xmod maxn; while(b1[i]<>0) and (b[i]<>x)and (i<maxn) do inc(i); b[i]:=x; inc(b1[i]);end; function find(x:longint):longint;var i,j:longint;begin i:=xmod maxn; while(a[i]<>x) and (i<maxn) do inc(i); find:=a1[i];end; function find1(x:longint):longint;var i,j:longint;begin i:=xmod maxn; while(b[i]<>x) and (i<maxn) do inc(i); find1:=b1[i];end; begin readln(n); fori:=1 to n do begin readln(x[i],y[i]); add(x[i]); add1(y[i]); end; fori:=1 to n do begin p:=find(x[i]); q:=find1(y[i]); ans:=ans+(p-1)*(q-1); end; writeln(ans); end.
1 0
- 2543. 【NOIP2011模拟9.1】直角三角形 (StandardIO)
- jzoj 2543. 【NOIP2011模拟9.1】直角三角形
- 2542. 【NOIP2011模拟9.1】统计 (StandardIO)
- 2541. 【NOIP2011模拟9.1】方格取数 (StandardIO)
- 【NOIP2011模拟9.1】直角三角形 (Standard IO)
- 2548. 【NOIP2011模拟9.4】最大正方形 (StandardIO)
- 2549. 【NOIP2011模拟9.4】家庭作业 (StandardIO)
- 2553. 【NOIP2011模拟9.7】射命丸文 (StandardIO)
- 2567. 【NOIP2011模拟9.17】电话时间 (StandardIO)
- 2568. 【NOIP2011模拟9.17】地铁建设 (StandardIO)
- 2569. 【NOIP2011模拟9.17】旅行 (StandardIO)Description
- 2557. 【NOIP2011模拟9.9】单词分类 (StandardIO)
- 2558. 【NOIP2011模拟9.9】过河问题 (StandardIO)
- 2559. 【NOIP2011模拟9.9】最短路 (StandardIO)
- 2570. 【NOIP2011模拟9.17】数字生成游戏 (StandardIO)
- 【模拟】 直角三角形
- jzoj 2542. 【NOIP2011模拟9.1】统计
- 【NOIP2011模拟9.1】统计 (Standard IO)
- JavaScript事件处理
- 【POJ】2346 - Lucky tickets(数位dp)
- Solrj创建doc/pdf/txt文件索引,高亮查询
- 第21课:scala文件和xml操作实战及spark源码鉴赏
- CentOS7:常用命令-笔记
- 2543. 【NOIP2011模拟9.1】直角三角形 (StandardIO)
- 1134 最长递增子序列
- map练习 统计参数个数
- CodeForce 675C 技巧题(其实我也不知道要归到什么里面去。。。)
- Crime
- Leetcode-pascals-triangle
- 数据结构之二叉树的建立与遍历
- 【1】【数学】CodeForces 588C Duff and Weight Lifting
- IplImage, CvMat, Mat 的关系