Codeforces Round #134 (Div. 2)
2012-08-18 17:40
302 查看
A. Mountain Scenery
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
View Code
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yi and yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
View Code
#include <iostream> #include<cstdio> #include<string.h> using namespace std; struct node { int x,y; }q[110]; int father[110]; int find(int x) { if(x!=father[x]) father[x] = find(father[x]); return father[x]; } int main() { int n,i,j,k,num = 0; scanf("%d", &n); for(i = 1; i <= n ;i++) { scanf("%d%d",&q[i].x,&q[i].y); } for(i = 1; i <= n ;i++) father[i] = i; for(i = 1; i < n ; i++) { for(j = i+1; j <= n ;j++) { if(q[j].x==q[i].x||q[j].y==q[i].y) { int px = find(i); int py = find(j); if(px!=py); father[px] = py; } } } for(i = 1; i <= n ; i++) if(father[i] == i) num++; printf("%d\n",num-1); return 0; }
相关文章推荐
- Codeforces Round #134 (Div. 2)——B
- Codeforces Round #134 (Div. 2) C. Ice Skating
- Codeforces Round #134 (Div. 2)
- Codeforces Round #134 (Div. 2)
- Codeforces Round #134 (Div. 2)
- 并查集Codeforces Round #134 (Div. 1), problem: (A) Ice Skating
- Codeforces Round #134 (Div. 2)A. Mountain Scenery
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #134 (Div. 2)C. Ice Skating
- Codeforces Round #134 (Div. 2)A. Mountain Scenery(简单)
- Codeforces Round #134 (Div. 2)A. Mountain Scenery(简单)
- Codeforces Round #134 (Div. 2) 并查集
- Codeforces Round #134 (Div. 2)
- Codeforces Round #134 (Div. 2) A. Mountain Scenery
- Codeforces Round #134 (Div. 2) B. Airport
- Codeforces Round 134 div 2 C题
- Codeforces Round #134 (Div. 2) A_B_C_D题
- Codeforces Round #429 (Div 2) A
- Codeforces Round #352 (Div. 2) B. Different is Good
- Codeforces Round #149 (Div. 2) E. XOR on Segment