hdu 5486 Difference of Clustering(暴力)
来源:互联网 发布:mysql 字段命名规范 编辑:程序博客网 时间:2024/05/17 09:16
题目链接:hdu 5486 Difference of Clustering
解题思路
枚举集合判断转移的方向只能从该集合的转移过去。
代码
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace std;const int maxn = 1e6 + 5;const int maxm = 1e5 + 5 * 7;int N, M, od[maxn], nw[maxn], P[maxn<<1];vector<int> L[maxm], R[maxm];void init () { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d%d", &od[i], &nw[i]); P[i<<1] = od[i]; P[(i<<1)|1] = nw[i]; } sort(P, P + 2 * N); M = unique(P, P + 2 * N) - P; for (int i = 0; i < M; i++) { L[i].clear(); R[i].clear(); } while(M > maxm); for (int i = 0; i < N; i++) { od[i] = lower_bound(P, P + M, od[i]) - P; nw[i] = lower_bound(P, P + M, nw[i]) - P; L[od[i]].push_back(nw[i]); R[nw[i]].push_back(od[i]); } for (int i = 0; i < M; i++) { sort(L[i].begin(), L[i].end()); od[i] = unique(L[i].begin(), L[i].end()) - L[i].begin(); sort(R[i].begin(), R[i].end()); nw[i] = unique(R[i].begin(), R[i].end()) - R[i].begin(); }}int main () { int cas; scanf("%d", &cas); for (int kcas = 1; kcas <= cas; kcas++) { init(); int a = 0, b = 0, c = 0; for (int i = 0; i < M; i++) { if (od[i] == 0) continue; bool flag = true; for (int j = 0; j < od[i] && flag; j++) flag = (nw[L[i][j]] == 1 && R[L[i][j]][0] == i); if (flag) { if (od[i] == 1) c++; else a++; for (int j = 0; j < od[i]; j++) nw[L[i][j]] = 0; od[i] = 0; } } for (int i = 0; i < M; i++) { if (nw[i] == 0) continue; bool flag = true; for (int j = 0; j < nw[i] && flag; j++) flag = (od[R[i][j]] == 1 && L[R[i][j]][0] == i); if (flag) { if (nw[i] == 1) c++; else b++; for (int j = 0; j < nw[i]; j++) od[R[i][j]] = 0; nw[i] = 0; } } printf("Case #%d: %d %d %d\n", kcas, a, b, c); } 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 5936 Difference 折半枚举,暴力
- hdu 4432 Sum of divisors(暴力)
- HDU 5019 Revenge of GCD (暴力)
- HDU 5578 Friendship of Frog(暴力)
- POJ:2718 Smallest Difference(暴力枚举)
- Smallest Difference (全排列 + 暴力?)
- hdu 5487 Difference of Languages BFS
- hdu 5487 Difference of Languages BFS
- 算法:“求质数”的题目(总结篇)
- git pull
- 将中序表达式转为后序表达式
- C++等级考试选择篇(二)
- MYSQL数据表分区详解
- hdu 5486 Difference of Clustering(暴力)
- 递归逆序字符串求字符串长度
- JAVA_SE基础——37.main方法的详解
- Git 更新操作
- 正则表达式详解——NSRegularExpression类和NSPredicate类的使用
- 函数入栈出栈以及栈帧
- Hibernate 抓取策略
- Mysql主从复制
- Git 执行更改 git commit