Difference of Clustering


Problem Description
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.

Let’s explain them with examples. Say in the old result, m0, m1, m2 are clustered into one cluster c0, but in the new result, m0 and m1 are clustered into c0, but m2 alone is clustered into c1. We denote the relationship like the following:
●  In the old, c0 = [m0, m1, m2]
●  In the new, c0 = [m0, m1], c1 = [m2]
There is no other members in the new c0 and c1. Then we say the old c0 is split into new c0 and new c1. A few more examples:
●  In the old, c0 = [m0, m1, m2]
●  In the new, c0 = [m0, m1, m2]. 
This is 1:1.
●  In the old, c0 = [m0, m1], c1 = [m2]
●  In the new, c0 = [m0, m1, m2]
This is merge. Please note, besides these relationship, there is another kind called “n:n”:
●  In the old, c0 = [m0, m1], c1 = [m2, m3]
●  In the new, c0 = [m0, m1, m2], c1 = [m3]
We don’t care about n:n. 
In this problem, we will give you two sets of clustering results, each describing the old and the new. We want to know the total number of splits, merges, and 1:1 respectively.

 
Input
The first line of input contains a number T indicating the number of test cases (T≤100).
Each test case starts with a line containing an integer N indicating the number of member entities (0≤N≤106 ). In the following N lines, the i-th line contains two integers c1 and c2, which means that the member entity with ID i is partitioned into cluster c1 and cluster c2 by the old algorithm and the new algorithm respectively. The cluster IDs c1 and c2 can always fit into a 32-bit signed integer.
 
Output
For each test case, output a single line consisting of “Case #X: A B C”. X is the test case number starting from 1. A, B, and C are the numbers of splits, merges, and 1:1s.
 
Sample Input
2
3
0 0
0 0
0 1
4
0 0
0 0
1 1
1 1
 
Sample Output
Case #1: 1 0 0
Case #2: 0 0 2
 
Source
 
题意:  给你n个关系,每个关系是a,b,表示a,b间连了一条边(注意要去重边),问你一对多,多对一,1对1的情况分别有多少种
         例如:样例1就是
                              0->1&&0->0
题解:  图论中的求出度,入度判断是哪种,STL大法
///
#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=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
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][],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=;
while(T--)
{
// init();
scanf("%d",&n);
mp.clear();
V1.clear();
V2.clear();
mpp2.clear();
mpp.clear();
vis.clear();
vis2.clear();
int k=;
FOR(i,,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]=;
vis2[b]=;
mp[make_pair(a,b)]=;
}
A=;
B=;
C=;
int sum;
for(int i=; i<V1.size(); i++)
{
sum=;
for(it=mpp[V1[i]].begin(); it!=mpp[V1[i]].end(); it++)
{
sum+=mpp2[*it].size();
}
if(sum==mpp[V1[i]].size())
{
if(sum==)
C++;
else
{
A++;
}
}
}
for(int i=; i<V2.size(); i++)
{
sum=;
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==)
C++;
else
{
B++;
}
}
}
printf("Case #%d: ",oo++);
cout<<A<<" "<<B<<" "<<C/<<endl; }
return ;
}

代码

HDU 5489 Difference of Clustering 图论的更多相关文章

  1. HDU 5486 Difference of Clustering 图论

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5486 题意: 给你每个元素一开始所属的集合和最后所属的集合,问有多少次集合的分离操作,并操作和不变操 ...

  2. HDU 5486 Difference of Clustering 暴力模拟

    Difference of Clustering HDU - 5486 题意:有n个实体,新旧两种聚类算法,每种算法有很多聚类,在同一算法里,一个实体只属于一个聚类,然后有以下三种模式. 第一种分散, ...

  3. HDU 5487 Difference of Languages(BFS)

    HDU 5487 Difference of Languages 这题从昨天下午2点开始做,到现在才AC了.感觉就是好多题都能想出来,就是写完后debug很长时间,才能AC,是不熟练的原因吗?但愿孰能 ...

  4. 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)

    HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...

  5. hdu 4715 Difference Between Primes

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you kn ...

  6. HDU 5489 Removed Interval (LIS变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...

  7. HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))

    Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  8. 【二分】【最长上升子序列】HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5489 题目大意: 一个N(N<=100000)个数的序列,要从中去掉相邻的L个数(去掉整个区间 ...

  9. HDU 5487 Difference of Languages

    Difference of Languages Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. ...

随机推荐

  1. 牛客多校Round 10

    咕咕咕.... 去烽火台和兵马俑了

  2. Hadoop Mapreduce 中的Partitioner

    Partitioner的作用的对Mapper产生的中间结果进行分片,以便将同一分组的数据交给同一个Reduce处理,Partitioner直接影响Reduce阶段的负载均衡. MapReduce提供了 ...

  3. PHP 锁机制

    应用环境 解决高并发,库存为负数的情况 阻塞模式 如果其他进程已经加锁文件,当前进程会一直等其他进程解锁文件后继续执行 flock($fp, LOCK_EX) // 文件锁 非阻塞模式 如果其他进程已 ...

  4. 关于字符串不为空 错误:s!=null

    错误:s!=null 正确:StringUtils.isNotBlank(s); public static boolean isBlank(CharSequence cs) { int strLen ...

  5. Spring常用注解总结 hibernate注解

    1.@Resource和@Autowired @Resource和@Autowired功能一样在容器查找匹配的Bean @Autowired默认按照byType方式进行bean匹配,@Resource ...

  6. HDU 1081 DP找最大和的矩阵

    题目大意: 在一个给定的大矩阵中找一个小型的矩阵,使这个矩阵中的元素和最大 可以先来看下面这个问题: 原来有做过在一个给定的数字序列中找一个最大和子序列,核心代码如下: ]; ]; ; ; int r ...

  7. noip模拟赛 运

    [问题背景]zhx 和妹子们玩数数游戏.[问题描述]仅包含 4 或 7 的数被称为幸运数.一个序列的子序列被定义为从序列中删去若干个数, 剩下的数组成的新序列.两个子序列被定义为不同的当且仅当其中的元 ...

  8. Uva548 Tree

    Tree You are to determine the value of the leaf node in a given binary tree that is the terminal nod ...

  9. NOIP1999 邮票面值设计

    题目描述 Description 给定一个信封,最多只允许粘贴N张邮票,计算在给定K(N+K≤40)种邮票的情况下(假定所有的邮票数量都足够),如何设计邮票的面值,能得到最大值MAX,使在1-MAX之 ...

  10. 洛谷—— P2049 魔术棋子

    https://www.luogu.org/problem/show?pid=2049 题目描述 在一个M*N的魔术棋盘中,每个格子中均有一个整数,当棋子走进这个格子中,则此棋子上的数会被乘以此格子中 ...