题意:

Xiaodao是一位喜欢参加ACM比赛的孩子.

所谓ACM比赛, 是一种团队比赛.


每一次比赛, 每队需要由恰好三位选手组成.


现在, Xiaodao希望组建一支新的队伍, 在这之前, 他需要知道每一位朋友有多少可能成为自己的好队友.

他计划给每一位朋友做出一个等级标号.

Xiaodao本人的等级标号为0.


如果一位朋友曾经和Xiaodao组队参加过比赛, 那么就标号为1.


如果一位朋友并没有与Xiaodao组队参加过比赛, 但是曾经与一位"与Xiaodao一起参加过比赛的人"组队参加过比赛. 那么就标号为2.


如果一位朋友无法标号为小于等于 k 的整数, 但是曾经与"标号为k的人"一起参加过比赛, 那么便可以标号为k+1.


其余的朋友们, 便无法给出编号, 我们记为"undefined".

现在, 我们给出了 n 组曾经参赛过的队伍, 每一组中给出了三位选手的名字.

我们希望知道每一位涉及到的选手应该被给予什么样的标号.

链接:点我

邻接表和邻接矩阵都没满分

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt,u,tot;
int c[MAXN][MAXN],dist[MAXN],vis[MAXN];
string a[MAXN];
struct Node
{
int to,next;
}edge[MAXN*];
int head[MAXN];
int tol;
void init()
{
tol=;
memset(head,-,sizeof(head));
}
void addedge(int a,int b)
{
edge[tol].to=b;
edge[tol].next=head[a];
head[a]=tol++;
edge[tol].to=a;
edge[tol].next=head[b];
head[b]=tol++;
}
void bfs()
{
queue<int> q;
cl(vis);
vis[u]=;
dist[u]=;
int now,next;
q.push(u);
while(!q.empty())
{
now=q.front();
q.pop();
for(int i=head[now];i!=-;i=edge[i].next)
{
next=edge[i].to;
if(!vis[next])
{
dist[next]=dist[now]+;
vis[next]=;
q.push(next);
}
}
}
}
map<string,int> mp;
string s="Xiaodao";
int main()
{
int i,j,k;
/*#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif*/
scanf("%d",&n);
tot=;
cl(c);
string s1,s2,s3;
bool flag=;
init();
int i1,i2,i3;
for(i=;i<n;i++)
{
cin>>s1,cin>>s2,cin>>s3;
if((s1==s||s2==s||s3==s)&&!flag) u=tot,flag=;
i1=mp[s1],i2=mp[s2],i3=mp[s3];
if(!mp[s1]) a[tot]+=s1,i1=mp[s1]=tot++;
if(!mp[s2]) a[tot]+=s2,i2=mp[s2]=tot++;
if(!mp[s3]) a[tot]+=s3,i3=mp[s3]=tot++;
addedge(i1,i2),addedge(i1,i3),addedge(i2,i3);
}
bfs();
sort(a+,a+tot+);
for(i=;i<=tot;i++)
{
int l=a[i].length();
if(l==) continue;
for(j=;j<l;j++)printf("%c",a[i][j]);
int id=mp[a[i]];
if(!vis[id]) printf(" undefined\n");
else printf(" %d\n",dist[id]);
}
}

vijos p1876 bfs+map的更多相关文章

  1. Catch That Cow POJ - 3278 bfs map超时,短路判断顺序。

    题意:可以把n边为n+1,n-1,n*2问从n到k的最少变化次数. 坑:标题写了.有点不会写bfs了... ac代码 #define _CRT_SECURE_NO_WARNINGS #include& ...

  2. PAT 甲级 1034 Head of a Gang (30 分)(bfs,map,强连通)

    1034 Head of a Gang (30 分)   One way that the police finds the head of a gang is to check people's p ...

  3. 845. 八数码(bfs+map)

    在一个3×3的网格中,1~8这8个数字和一个“X”恰好不重不漏地分布在这3×3的网格中. 例如: 1 2 3 X 4 6 7 5 8 在游戏过程中,可以把“X”与其上.下.左.右四个方向之一的数字交换 ...

  4. 小花梨判连通 (bfs+思维+map统计数量)

    如果两个集合存储颜色的情况相同,说明这两个在k个图中都是在一个集合的 学到的点:用map,将vector映射一个整数时,只有vector后面的邻接的数据都一样时,才认为两个vector一样 代码: # ...

  5. hdu.1067.Gap(bfs+hash)

    Gap Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  6. 最少步数(dfs + bfs +bfs优化)

    最少步数 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 这有一个迷宫,有0~8行和0~8列: 1,1,1,1,1,1,1,1,1 1,0,0,1,0,0,1,0,1 ...

  7. DFS和BFS

    BFS 代码步骤: 1.写出每个点和每个点的邻接点的对应关系 2.方法参数:传一个对应关系和起始点 3.创建一个队列,然后每次都移除第一个,然后把移除的邻接点添加进去,打印取出的第一个,然后循环,一直 ...

  8. BFS搜索算法应用_Codevs 1004 四子连棋

    #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <cs ...

  9. hdu 5025 bfs+状压

    http://acm.hdu.edu.cn/showproblem.php?pid=5025 N*N矩阵 M个钥匙 K起点,T终点,S点需多花费1点且只需要一次,1-9表示9把钥匙,只有当前有I号钥匙 ...

随机推荐

  1. sql 内联,左联,右联,全联

    联合查询效率较高,以下例子来说明联合查询(内联.左联.右联.全联)的好处: T1表结构(用户名,密码) userid (int) username varchar(20) password  varc ...

  2. MVVM模式用依赖注入的方式配置ViewModel并注册消息

    最初的想法 这次主要讨论下给View指定ViewModel的事情.一般来说给View指定ViewModel常用的方式有两种,一种是在View的后台代码中写DataContext = new ViewM ...

  3. openjudge-NOI 2.5-1700 八皇后问题

    题目链接:http://noi.openjudge.cn/ch0205/1700/ 题解: 经典深搜题目…… #include<cstdio> ][]; int num; void pri ...

  4. 八、springcloud之服务网关zuul(一)

    一.Zuul简介 zuul 是netflix开源的一个API Gateway 服务器, 本质上是一个web servlet应用. Zuul是Netflix出品的一个基于JVM路由和服务端的负载均衡器. ...

  5. 03 Editor plugins and IDEs 编辑器插件和 ide

    Editor plugins and IDEs  编辑器插件和 ide Introduction  介绍 Options 选项   Introduction 介绍 This document list ...

  6. Token机制,防止web页面重复提交

    1.业务要求:页面的数据只能被点击提交一次 2.发生原因: 由于重复点击或者网络重发,或者nginx重发等情况会导致数据被重复提交 3.解决办法: 集群环境:采用token加redis(redis单线 ...

  7. Python_oldboy_自动化运维之路(二)

    本节内容: 1.pycharm工具的使用 2.进制运算 3.表达式if ...else语句 4.表达式for 循环 5.break and continue 6.表达式while 循环 1.pycha ...

  8. 获取矩形局域的方法,Rect、Bounds、Point

    获取一个点和矩形区域的方法如下: var R: TRect; procedure TForm5.FormCreate(Sender: TObject); begin RadioGroup1.Items ...

  9. java小爬虫

    爬取煎蛋网 1.找出页面网址的规律 2.设计页面图片网址的正则 代码: import java.io.BufferedInputStream; import java.io.BufferedOutpu ...

  10. Django数据库数据表操作

    建立表单 django通过设置类来快速建表,打开models.py 例: from __future__ import unicode_literals from django.db import m ...