HDU 5489 Difference of Clustering 图论
2015-10-25 15:25
141 查看
Difference of Clustering
[align=left]Problem Description[/align]Given two clustering algorithms, the old and the new, you want to find the difference between their results.
A clustering algorithm takes many member entities as input and partition them into clusters. In this problem, a member entity must be clustered into exactly one cluster. However, we don’t have any pre-knowledge of the clusters, so different algorithms may produce different number of clusters as well as different cluster IDs. One thing we are sure about is that the memberIDs are stable, which means that the same member ID across different algorithms indicates the same member entity.
To compare two clustering algorithms, we care about three kinds of relationship between the old clusters and the new clusters: split, merge and 1:1. Please refer to the figure below.
///1085422276 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<cmath> #include<map> #include<bitset> #include<set> #include<vector> using namespace std ; typedef __int64 ll; #define mem(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,127,sizeof(a)); #define memfy(a) memset(a,-1,sizeof(a)); #define TS printf("111111\n"); #define FOR(i,a,b) for( int i=a;i<=b;i++) #define FORJ(i,a,b) for(int i=a;i>=b;i--) #define READ(a,b,c) scanf("%d%d%d",&a,&b,&c) #define mod 1000000007 #define inf 100000000 inline ll read() { ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } //**************************************** #define maxn 1000000+6 struct ss { int to,next; } e[maxn]; struct node { int x,index;//0,1; }; int head[maxn],n,a,b,t,in[maxn][2],A,B,C; map<pair<int ,int >,int >mp; map<int ,int >vis,vis2; map<int ,vector<int > >mpp,mpp2; vector<int >V1,V2; vector<int >::iterator it;; int main() { int T=read(); int oo=1; while(T--) { // init(); scanf("%d",&n); mp.clear(); V1.clear(); V2.clear(); mpp2.clear(); mpp.clear(); vis.clear(); vis2.clear(); int k=0; FOR(i,1,n) { scanf("%d%d",&a,&b); if(mp[make_pair(a,b)])continue; mpp[a].push_back(b); mpp2[b].push_back(a); if(!vis[a]) V1.push_back(a); if(!vis2[b]) V2.push_back(b); vis[a]=1; vis2[b]=1; mp[make_pair(a,b)]=1; } A=0; B=0; C=0; int sum; for(int i=0; i<V1.size(); i++) { sum=0; for(it=mpp[V1[i]].begin(); it!=mpp[V1[i]].end(); it++) { sum+=mpp2[*it].size(); } if(sum==mpp[V1[i]].size()) { if(sum==1) C++; else { A++; } } } for(int i=0; i<V2.size(); i++) { sum=0; for(it=mpp2[V2[i]].begin(); it!=mpp2[V2[i]].end(); it++) { sum+=mpp[*it].size(); } if(sum==mpp2[V2[i]].size()) { //cout<<mpp[V2[i]].size()<<endl; if(sum==1) C++; else { B++; } } } printf("Case #%d: ",oo++); cout<<A<<" "<<B<<" "<<C/2<<endl; } return 0; }
代码
相关文章推荐
- CSS3 animation 属性
- 使用Jsoup 抓取页面的数据
- js Array类型
- 自定义spinner样式
- js图片文字上下自动滚动
- cssZ-index,背景图片,权重
- background-size:cover
- 《基于MVC的JavaScript Web富应用开发》 电子工业出版社 (三)
- JS创建对象
- JavaScript编程中布尔对象的基本使用
- css相对定位,绝对定位,static定位
- 《WEB前端黑客技术揭秘》基础知识(一)
- z-index:9999在CSS中是什么意思
- 举例讲解JavaScript中将数组元素转换为字符串的方法
- web前端之HTML常用标签,元素,属性
- HTML, 超文本标记语言, 描述网页结构
- 利用Data URL(data:image/jpg;base64,)加速网页加载的方法
- 总结js中数据类型的bool值及其比较
- 在JSP中动态生成随机验证码,登录时后台校验验证码,以及如何避免同一个验证码被重复提交爆破密码
- LeetCode OJ:Count Complete Tree Nodes(完全二叉树的节点数目)