TOJ Right Triangles II
来源:互联网 发布:英文网络用语 编辑:程序博客网 时间:2024/05/17 04:03
Right Triangles II
Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByte
Total Submit: 53 Accepted: 14
Total Submit: 53 Accepted: 14
Description
N points are placed in the coordinate plane.
Write a program that calculates how many ways we can choose three points so that they form a right triangle with legs parallel to the coordinate axes.
A right triangle has one 90-degree internal angle. The legs of a right triangle are its two shorter sides.
Input
The first line of input contains the integer N (3 ≤ N ≤ 100 000), the number of points.
Each of the following N lines contains two integers X and Y (1 ≤ X, Y ≤ 100 000), the coordinates of one point.
No pair of points will share the same pair of coordinates.
Output
Output the number of triangles.
Sample Input
34 22 11 3
Sample Output
0
Uploader
crq
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int maxn = 100008;vector<__int64> x[maxn];__int64 y[maxn];int n;void work() { __int64 i, j; __int64 cnt = 0; for(i = 1; i < maxn; i++) {//maxn --> n !!! __int64 Size = x[i].size(); if(Size <= 1) continue; for(j = 0; j < Size; j++) { __int64 id = x[i][j]; if(y[id] > 0) cnt += (Size - 1) * (y[id] - 1); } } printf("%I64d\n", cnt);}void init() { int i; for(i = 0; i < maxn; i++) { x[i].clear(); y[i] = 0; }}int main(){ int i; int dx, dy; while(scanf("%d", &n) != EOF) { init(); for(i = 0; i < n; i++) { scanf("%d%d", &dx, &dy); x[dx].push_back(dy); y[dy]++; } work(); } return 0;}
- TOJ Right Triangles II
- Right Triangles
- Right Triangles
- TOJ 2746: Classifying Triangles
- No_39Integer right triangles
- Euler: Integer right triangles
- Codeforces 52B Right Triangles
- Project Euler-Integer right triangles
- [TOJ 3978] Probability II
- Isosceles Right Triangles 坐标暴力枚举
- codeforces 52B - Right Triangles 组合数
- codechef Chef and The Right Triangles 题解
- Problem 39—Integer right triangles
- Project Euler:Problem 39 Integer right triangles
- Problem 39 Integer right triangles (数学)
- CodeForces 52 B.Right Triangles(水~)
- TOJ 1701: Face The Right Way
- TOJ 1650 Flying Right -- 贪心 + 线段树
- Flash图表组件FusionCharts帮助文档五:用BOM实现多语言(UTF-8)
- Flash图表组件FusionCharts帮助文档六:在地图上作标记
- Flash图表组件FusionCharts帮助文档七:加载多个图表文件
- Flash图表组件FusionCharts帮助文档八:添加向下钻取链接
- Flash图表组件FusionCharts帮助文档九:网格组件用法
- TOJ Right Triangles II
- ARM MMU工作原理剖析
- Flash图表组件FusionCharts帮助文档十:将柱状图转换为饼状图
- TwinCAT与AMD的处理器的不兼容问题
- Flash图表组件FusionCharts帮助文档十一:Excel静态数据变为动态图表
- Flash图表组件FusionCharts帮助文档十二:创建透明图表
- Flash图表组件FusionCharts帮助文档十三:调整图表比例(百分比)
- Android Password Field Example
- TOJ 4224 Cryptologist