题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4039

题目分类:字符串+bfs

题意:给一个人际关系图,根据关系图,给一个人推荐一个人认识

题目分析:

根据样例画出的关系图

代码:

#include<bits/stdc++.h>

using namespace std;

const int N=;

map<string,int>mp;
vector<int>G[N*];
vector<string> ans; char s1[];
char s2[];
char ss[]; char s[N*][];
int Stack[N*];
int vis[N*]; bool bfs(int u)
{
memset(vis,,sizeof(vis));
vis[u]=-;
queue<int>q;
for(int i=;i<G[u].size();i++)
{
q.push(G[u][i]);
vis[G[u][i]]=-;
}
int siz=-;
int company=;
while(!q.empty())
{
u=q.front();
q.pop();
for(int i=;i<G[u].size();i++)
{
int v=G[u][i];
if(vis[v]==-) continue;
vis[v]++;
if(siz<vis[v])
{
siz=vis[v];
company=;
Stack[]=v;
}
else if(siz==vis[v])
{
Stack[company++]=v;
}
}
}
if(siz<) return false;
ans.clear(); for(int i=;i<company;i++)
ans.push_back(s[Stack[i]]);
sort(ans.begin(),ans.end()); for(int i=;i<ans.size();i++)
{
cout<<ans[i];
if(i<ans.size()-)
printf(" ");
}
printf("\n");
return true;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif int t,n,m;
scanf("%d",&t);
for(int kase=;kase<=t;kase++)
{
mp.clear();
scanf("%d %d",&n,&m);
for(int i=;i<=*n;i++)
G[i].clear();
int top=;
int num1,num2;
while(n--)
{
scanf("%s %s",s1,s2);
if(mp.find(s1)==mp.end())
{
mp[s1]=++top;
memcpy(s[top],s1,sizeof s1);
num1=top;
}
else
num1=mp.find(s1)->second; if(mp.find(s2)==mp.end())
{
mp[s2]=++top;
memcpy(s[top],s2,sizeof s2);
num2=top;
}
else
num2=mp.find(s2)->second; G[num1].push_back(num2);
G[num2].push_back(num1);
}
printf("Case %d:\n",kase);
while(m--)
{
scanf("%s",ss);
int i=mp.find(ss)->second;
if(bfs(i)==false)
puts("-");
}
}
return ;
}

hdu 4039 The Social Network的更多相关文章

  1. Call for Papers IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM)

    IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...

  2. [CareerCup] 10.2 Data Structures for Large Social Network 大型社交网站的数据结构

    10.2 How would you design the data structures for a very large social network like Facebook or Linke ...

  3. Social Network Analysis的Centrality总结,以及networkx实现EigenCentrality,PageRank和KatzCentrality的对比

    本文主要总结近期学习的Social Network Analysis(SNA)中的各种Centrality度量,我暂且翻译为中心度.本文主要是实战,理论方面几乎没有,因为对于庞大的SNA,我可能连门都 ...

  4. IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 Industry Track Call for Papers

    IEEE/ACM International Conference on Advances in Social Network Analysis and Mining (ASONAM) 2014 In ...

  5. 社会网络分析——Social Network Analysis

    什么是社会网络分析,英文social network analysis.现在这个分析越来越时髦,也越来越显现其在社会科学的研究价值.我在2000年的时候受祝建华老师的邀请到香港城市大学作研究,接触到 ...

  6. Social Network 社交网络分析

    Social Network 社交网络分析 一:什么是SNA-社交网络分析 社交网络分析的威力何在?我想几个案例来说明. 案例1:对一个毫无了解的组织(这个组织可以是一个公司,亦或是一个组织),如果能 ...

  7. Complex social network Partition for Balanced Subnetworks---Hao Lan Zhang,Jiming Liu,Chunyu Feng,Chaoyi Pang,Tongliang Li,Jing He阅读

    摘要:Abstract—Complex social network analysis methods have been applied extensively in various domains ...

  8. Coursera Algorithms week1 查并集 练习测验:1 Social network connectivity

    题目原文描述: Given a social network containing. n members and a log file containing m timestamps at which ...

  9. Codeforces Round #590 (Div. 3) B2. Social Network (hard version)

    链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard ver ...

随机推荐

  1. img标签中的src为php文件

    先来看个例子: <img src="imgcode.php" alt="看不清楚,换一张" style="cursor: pointer;&qu ...

  2. hdu 1282回文数猜想

    http://acm.hdu.edu.cn/showproblem.php?pid=1282 Problem Description 一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序 ...

  3. Bernstein polynomials

    Bernstein多项式能够用来一致逼近闭区间上的连续函数. 对于[0,1]上的连续函数f(x),定义Bernstein多项式 B_n(f,x) = sum{k=0..n} f(k/n)C(k,n)t ...

  4. Netty In Action中文版 - 第五章:Buffers(缓冲)

    本章介绍 ByteBuf ByteBufHolder ByteBufAllocator 使用这些接口分配缓冲和运行操作 每当你须要数据传输时,它必须包括一个缓冲区.Java NIO API自带的缓冲区 ...

  5. 第1章 软件测试基本概念(Week1,3月3日)

    一.对软件的认识 1. 什么是软件 2. 软件的分类 3. 软件开发的生命周期模型 (1)瀑布模型 (2)Scrum 其实对用瀑布模型这种臃肿不堪.要求严格.而无法适应软件开发周期变化的开发模型,渐渐 ...

  6. MySQL推出Applier,可实时复制数据到Hadoop

    MySQL复制操作可以将数据从一个MySQL服务器(主)复制到其他的一个或多个MySQL服务器(从).试想一下,如果从服务器不再局限为一个MySQL服务器,而是其他任何数据库服务器或平台,并且复制事件 ...

  7. protected的一些功能

    java的访问限制有private.protected.public.这里只想进一步认识一下protected. 我对protected有4个疑问: 1,在相同包中,是否可以调用其它类的protect ...

  8. asp.net2.0安全性(2)--用户个性化设置(1)--转载来自车老师

    在Membership表中可以存储一些用户的基本信息,但有的时候,我们需要记录的用户信息远远不止Membership表中提供的这些,如QQ.MSN.家庭住址.联系电话等等.那如何把这些用户信息记录到数 ...

  9. 微软vs2015先行,Visual Studio 2015正式版离线iso及在线下载(附key)附带百度云盘地址

    win10正式版发布之前我们迎来了vs2015正式版,迫不及待要下载朋友可以看看 Visual Studio Community 2015简体中文版(社区版,针对个人免费): 在线安装exe:http ...

  10. QQ邮箱中转站文件即将过期时如何转存到微云

    今天QQ邮箱提示我的中转站有个文件即将过期,然后我看看了那个文件然后我想永久保存这个文件,腾讯有个微云网盘(好像有10T),想知道能不能保存到微云已变永久保存 结果发现在文件中转站这个界面竟然没有续期 ...