思路:用map将每个字符串与一个数字进行对应,然后暴力统计就好了

#include<cstring>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#define Maxn 2010
using namespace std;
int fr[Maxn][Maxn],mul[Maxn][Maxn],Max[Maxn];
char str[Maxn][];
map<string,int> g;
vector<int> head[Maxn*];
vector<int> ans[Maxn*];
int cmp(int a,int b)
{
return strcmp(str[a],str[b])<;
}
int main()
{
int t,n,q,i,j,k,Case=,u,v;
scanf("%d",&t);
char s1[],s2[];
while(t--)
{
memset(fr,,sizeof(fr));
memset(mul,,sizeof(mul));
memset(Max,,sizeof(Max));
g.clear();
scanf("%d%d",&n,&q);
for(i=;i<=*n;i++)
head[i].clear(),ans[i].clear();
int cnt=;
for(i=;i<=n;i++)
{
scanf("%s %s",&s1,&s2);
if(!g[s1]){
g[s1]=++cnt;
strcpy(str[cnt],s1);
}
if(!g[s2]){
g[s2]=++cnt;
strcpy(str[cnt],s2);
}
u=g[s1],v=g[s2];
head[u].push_back(v);
head[v].push_back(u);
fr[u][v]=fr[v][u]=;
}
int sz;
for(i=;i<=cnt;i++){
sz=head[i].size();
for(j=;j<sz;j++){
u=head[i][j];
int ss=head[u].size();
for(k=;k<ss;k++){
v=head[u][k];
if(!fr[i][v]&&i!=v)
mul[i][v]++,Max[i]=max(Max[i],mul[i][v]);
}
}
}
for(i=;i<=cnt;i++){
for(j=;j<=cnt;j++){
if(j==i) continue;
if(mul[i][j]==Max[i]&&Max[i])
ans[i].push_back(j);
}
sort(ans[i].begin(),ans[i].end(),cmp);
}
printf("Case %d:\n",++Case);
//cout<<q<<endl;
for(i=;i<=q;i++){
scanf("%s",s1);
u=g[s1];
if(ans[u].empty())
printf("-");
else{
sz=ans[u].size();
v=ans[u][];
printf("%s",str[v]);
for(j=;j<sz;j++){
v=ans[u][j];
printf(" %s",str[v]);
}
}
printf("\n");
}
}
return ;
}

hdu 4039 暴力的更多相关文章

  1. hdu 4039 The Social Network

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4039 题目分类:字符串+bfs 题意:给一个人际关系图,根据关系图,给一个人推荐一个人认识 题目分析: ...

  2. HDU 6351暴力枚举 6354计算几何

    Beautiful Now Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  3. HDU 5944 暴力

    Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)T ...

  4. hdu 4952 暴力

    http://acm.hdu.edu.cn/showproblem.php?pid=4952 给定x,k,i从1到k,每次a[i]要是i的倍数,并且a[i]大于等于a[i-1],x为a0 递推到下一个 ...

  5. hdu 4708(暴力+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数 ...

  6. HDU - 6183 暴力,线段树动态开点,cdq分治

    B - Color itHDU - 6183 题目大意:有三种操作,0是清空所有点,1是给点(x,y)涂上颜色c,2是查询满足1<=a<=x,y1<=b<=y2的(a,b)点一 ...

  7. HDU 5386 暴力

    题目 也是个坑题,可惜没有发现这是个水题,被矩阵的气势吓住了,其实后来做出来的人挺多,就应该想到没那么难了.(两个队友陷入DP无法自拔,没有想换题的打算). 题意:告诉初始矩阵,目的矩阵,告诉n个步骤 ...

  8. hdu 4039 2011成都赛区网络赛I ***

    两层搜索,直接for循环就行了,还要注意不能是自己的朋友 #include<cstdio> #include<iostream> #include<algorithm&g ...

  9. hdu 4007 暴力or线段树 ***

    尼玛,INF不能定义太大,找标程对拍了好久 #include<cstdio> #include<iostream> #include<algorithm> #inc ...

随机推荐

  1. Unable to generate a temporary class (result=1)解决方法

    Unable to generate a temporary class (result=1).error CS2001: Source file 'C:\WINDOWS\TEMP\ug5v9uxt. ...

  2. android开发中提示:requires permission android.permission write_settings解决方法

    一.在Manifest.xml 中添加: <uses-permission android:name="android.permission.WRITE_CONTACTS" ...

  3. android 拨打电话小功能

    1.其实就是对Intent 的ACTION进行参数设置. 在manifest中药设置打电话的权限: <uses-permission android:name="android.per ...

  4. Freescale OSBDM JM60仿真器

    OSBDM-JM60 - 9S08JM60 Based OSBDM — It includes interfaces and firmware applied to all the targets s ...

  5. Codeforces Gym 100803D Space Golf 物理题

    Space Golf 题目连接: http://codeforces.com/gym/100803/attachments Description You surely have never hear ...

  6. SVM-支持向量机算法概述

    (一)SVM的背景简单介绍 支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本.非线性及高维模式识别中表现出很多特有的优势,并 ...

  7. static使用方法小结

    static使用方法小结 statickeyword是C, C++中都存在的keyword, 它主要有三种使用方式, 当中前两种仅仅指在C语言中使用, 第三种在C++中使用(C,C++中详细细微操作不 ...

  8. 使用ajax和window.history.pushState无刷新改变页面内容和地址栏URL

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  9. 都是类型惹的祸——小心unsigned

    正如我们所知道的,编程语句都有很多的基本数据类型,如char,inf,float等等,而在C和C++中还有一个特殊的类型就是无符号数,它由unsigned修饰,如unsigned int等.大家有没想 ...

  10. 使用AutoMapper实现Dto和Model的自由转换

    AutoMapper是一个.NET的对象映射工具. 项目地址:https://github.com/AutoMapper/AutoMapper. 帮助文档:https://github.com/Aut ...