hdu 5486 Difference of Clustering
来源:互联网 发布:java关键字 false 编辑:程序博客网 时间:2024/06/04 20:18
题意:
略
思路:
这题杭电的oj卡内存有点恶心,在杭电oj,vector不能乱用。。
看完题解这题感觉好简单的说。。。
首先把输入的值进行离散化,离散化完之后大概有1e5个左右。
然后用vector分l,r保存集合之间的连线。
split:左边的度数>1,对应左边的任意一个集合度数 = 1;
merge:换过来做,就变成了split了;
1:1:左右两边的度数都是1;
code:(sort、unique用的灰起)
#include <bits/stdc++.h>using namespace std;const int N = 1e6+5;const int M = 1e5+50;typedef long long LL;vector <int> l[M], r[M];int n;int h[N<<1];int x[N], y[N];void solve() { sort(h, h+2*n); int m = unique(h, h+2*n)-h; for(int i = 0;i < m; i++) l[i].clear(), r[i].clear(); for(int i = 0;i < n; i++) { x[i] = lower_bound(h, h+m, x[i])-h; y[i] = lower_bound(h, h+m, y[i])-h; l[x[i]].push_back(y[i]); r[y[i]].push_back(x[i]); } for(int i = 0;i < m; i++) { sort(l[i].begin(), l[i].end()); l[i].erase(unique(l[i].begin(), l[i].end()), l[i].end()); sort(r[i].begin(), r[i].end()); r[i].erase(unique(r[i].begin(), r[i].end()), r[i].end()); } int a, b, c; a = b = c = 0; for(int i = 0;i < m; i++) { if(l[i].size() == 0) continue; bool flag = true; for(auto &it:l[i]) { if(r[it].size() == 1 && r[it][0] == i) continue; flag = false; break; } if(flag) { if(l[i].size() == 1) c++; else a++; } } for(int i = 0;i < m; i++) { if(r[i].size() == 0) continue; bool flag = true; for(auto &it:r[i]) { if(l[it].size() == 1 && l[it][0] == i) continue; flag = false; break; } if(flag) { if(r[i].size() == 1) c++; else b++; } } printf("%d %d %d\n", a, b, c/2);} int main() { int T, cas = 0; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 0;i < n; i++) { scanf("%d%d", &x[i], &y[i]); h[i<<1] = x[i]; h[i<<1|1] = y[i]; } printf("Case #%d: ", ++cas); solve(); } return 0;}
0 0
- hdu 5486 Difference of Clustering
- hdu 5486 Difference of Clustering
- HDU 5486(Difference of Clustering-聚类)
- hdu 5486 Difference of Clustering(暴力)
- HDU 5486 Difference of Clustering 图论
- hdu 5486 Difference of Clustering(合肥网赛)
- HDU5486-Difference of Clustering
- hdu 5486 Difference of Clustering 2015多校联合训练赛
- hdu 5486 Difference of Clustering 2015合肥网络赛 并查集 离散化 悲伤的题
- hdu 5487 Difference of Languages(bfs)
- hdu 5487 Difference of Languages BFS
- hdu 5487 Difference of Languages BFS
- Difference of Gaussian (DoG)
- hdu 4161 Iterated Difference
- hdu 4598 Difference
- HDU 4598 Difference
- HDU 4161 Iterated Difference
- hdu 5936 Difference 二分
- 玩转vsftpd服务器的四大高级配置
- 1103 host is not allowed to connect to this mysql server
- 矩阵的加法运算
- QT中的内存管理一个小经验
- C#学习日记06---数据类型 之 浮点数类型
- hdu 5486 Difference of Clustering
- HTML5 Form Data 对象的使用-jQuery
- UIScrollView与NSTimer计时器、分页指示器控件的使用
- Java 用hashmap统计词频
- 使用多态的注意事项
- 定位服务 CLLocationManager 的简单用法
- 网站推荐大全
- 随笔分类 - 无废话ExtJs系列教程
- JAVA注解