forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10574.cpp
125 lines (123 loc) · 1.65 KB
/
10574.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <bits/stdc++.h>
using namespace std;
/*
10574
Counting Rectangles
*/
#define MAXN 5005
int np;
struct ss
{
int x, y;
} point[MAXN], dum;
int A[5000], B[5000];
int cur, inda, indb;
int com(const void *a, const void *b)
{
ss *p, *q;
p = (ss *)a;
q = (ss *)b;
if (p->x == q->x)
{
return p->y - q->y;
}
return p->x - q->x;
}
int com1(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
int Match()
{
int i, j, count = 0, mt = 0;
int p = 0, f = B[indb - 1];
for (i = 0; i < inda; i++)
{
if (A[inda - 1] < B[p])
{
break;
}
for (j = p; j < indb; j++)
{
if (A[i] < B[j])
{
p = j;
break;
}
if (A[i] == B[j])
{
mt++;
p = j + 1;
break;
}
}
}
count = (mt * (mt - 1)) / 2;
return count;
}
int Cal(int mm)
{
int j, nt, count = 0;
cur = point[mm].x;
indb = 0;
nt = mm;
cur = point[nt].x;
while (nt < np)
{
for (j = nt; j < np && point[j].x == cur; j++)
{
B[indb++] = point[j].y;
}
if (indb > 1)
{
count += Match();
}
nt = j;
cur = point[nt].x;
indb = 0;
}
return count;
}
void Select()
{
int i, k, c = 0;
int nt = 0, cur = point[0].x;
while (nt < np)
{
k = 0;
inda = 0;
for (i = nt; i < np && point[i].x == cur; i++)
{
A[inda++] = point[i].y;
}
nt = i;
if (nt >= np - 1)
{
break;
}
cur = point[i].x;
if (inda <= 1)
{
continue;
}
c += Cal(nt);
}
printf("%d\n", c);
}
int main()
{
int kase, i, f = 1;
scanf("%d", &kase);
while (kase--)
{
scanf("%d", &np);
for (i = 0; i < np; i++)
{
scanf("%d%d", &point[i].x, &point[i].y);
}
qsort(point, np, sizeof(point[0]), com);
printf("Case %d: ", f++);
Select();
}
return 0;
}