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 ...
随机推荐
- shell登录模式及其相应配置文件(转)
参考<linux命令.编辑器与shell编程>(清华大学出版社) 当启动shell时,它将运行启动文件来初始化自己.具体运行哪个文件取决于该shell是登陆shell还是非登陆shell的 ...
- linux i2c驱动架构-dm368 i2c驱动分析
linux i2c驱动架构-dm368 i2c驱动分析 在阅读本文最好先熟悉一种i2c设备的驱动程序,并且浏览一下i2c-core.c以及芯片提供商的提供的i2c总线驱动(i2c-davinc ...
- 【iOS发展-53】实例探究:scrollView使用方法和解决方案无法滚动核心
案例效果: (1)基本的就是练习scrollView的使用方法.界面里面的其它元素基本都是UIView和UIButton堆砌起来的. (2)主要用代码实现.当然,能够先用storyboard拖个scr ...
- PHP - 操作MySQL数据库
第16章 PHP操作MySQL 学习要点: 1.PHP连接到MySQL 2.增删改查 3.其他常用函数 如果你已经具有了使用PHP.SQL和MySQL的丰富经验,现在就可以把所有这些技术组合在一起.P ...
- 读取中兴3G告警log告警文件到集合
1.文件格式 ALARM_ID=102305_404205 EVENT_TIME=-- :: NOTIFICATION_TYPE= MANAGED_OBJECT_INSTANCE=NodeId=,Bs ...
- 基于visual Studio2013解决C语言竞赛题之1042字符串比较
题目 解决代码及点评 /********************************************************************** ...
- java绘图板
JAVA绘图板 import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Button; import ja ...
- CppCMS URL使用
Artyom觉得URL分为三个组成部分: Script_Name / Path_Info ? Query_String 比方以下的: /foo/bar.php/test?x=10 Script_Nam ...
- Linux改动文件权限记录
1.从文件类型上分可分为三种, 用ls-l查询,以"一"开头的是文件,以字母"d"开头的是文件夹(俗称文件夹),以字母"l"开头的是连接. ...
- python 默认编码( UnicodeDecodeError: 'ascii' codec can't decode)
python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't deco ...