hdu 4039 The Social Network
题目链接: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的更多相关文章
- 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 ...
- [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 ...
- Social Network Analysis的Centrality总结,以及networkx实现EigenCentrality,PageRank和KatzCentrality的对比
本文主要总结近期学习的Social Network Analysis(SNA)中的各种Centrality度量,我暂且翻译为中心度.本文主要是实战,理论方面几乎没有,因为对于庞大的SNA,我可能连门都 ...
- 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 ...
- 社会网络分析——Social Network Analysis
什么是社会网络分析,英文social network analysis.现在这个分析越来越时髦,也越来越显现其在社会科学的研究价值.我在2000年的时候受祝建华老师的邀请到香港城市大学作研究,接触到 ...
- Social Network 社交网络分析
Social Network 社交网络分析 一:什么是SNA-社交网络分析 社交网络分析的威力何在?我想几个案例来说明. 案例1:对一个毫无了解的组织(这个组织可以是一个公司,亦或是一个组织),如果能 ...
- 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 ...
- Coursera Algorithms week1 查并集 练习测验:1 Social network connectivity
题目原文描述: Given a social network containing. n members and a log file containing m timestamps at which ...
- 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 ...
随机推荐
- 怎样让js不产生冲突,避免全局变量的泛滥,合理运用命名空间
为了避免变量之间的覆盖与冲突.能够生成命名空间.命名空间是一种特殊的前缀,在js中,通过{ }对象实现. 在不同的匿名函数中,依据功能声明一个不同的命名空间,每一个匿名函数中GLOBAL对象的属性都不 ...
- MongoDB(二)——安装配置了解
前边介绍了MongoDB的大概理论知识,这篇来对MongoDB进行一下安装使用,支持安装在windows和linux上,当然了很多其它情况下我们是安装在linux上,由于毕竟server用linux的 ...
- NSThread的一些细节
1.NSThread创建方式(一个NSThread对象就代表一条线程)1.1>创建\启动线程(1)线程一启动,就会在thread中执行self的run方法NSTread *thread = [[ ...
- delphi高手突破之异常及错误处理
什么是异常?为什么要用它? 所谓“异常”是指一个异常类的对象.Delphi的VCL中,所有异常类都派生于Exception类.该类声明了异常的一般行为.性质.最重要的是,它有一个Message属性可以 ...
- 基于visual Studio2013解决C语言竞赛题之1022最大数最小数
题目 解决代码及点评 /************************************************************************/ ...
- boost操作xml 5分钟官方教程
Five Minute Tutorial This tutorial uses XML. Note that the library is not specifically bound to XML, ...
- 代码格式化工具Astyle配置
Astyle是一个很好的代码格式化工具,其他不多说,下面介绍一下我在VS 2010的配置 1. http://sourceforge.net/projects/astyle,这是该插件的网站,下载后把 ...
- HttpWebRequest 基础连接已经关闭: 接收时发生错误
HttpWebRequest request = null; Stream webStream = null; HttpWebResponse response = null; StreamReade ...
- Tesseract Ocr引擎
Tesseract Ocr引擎 1.Tesseract介绍 tesseract 是一个google支持的开源ocr项目,其项目地址:https://github.com/tesseract-ocr/t ...
- webstorm与phpstorm主题配置
原创. 更换webstorm的主题的,照着网上的教程试了好多次都发现不行,而且我之前有个同学也是这样的问题,找不到相关的colors文件夹,所以在网上教程的基础上对于更改主题做了细微的修改. 1.下载 ...