ural 1837 Isenbaev's Number
http://acm.timus.ru/problem.aspx?space=1&num=1837
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
vector<int>q[]; struct node
{
string s;
int num;
bool operator <(const node &a)const
{
return s<a.s;
}
} p1[*];
int t1; int getnum(string c)
{
for(int i=; i<t1; i++)
{
if(c==p1[i].s) return i;
}
p1[t1++].s=c;
return t1-;
} void bfs(int str)
{
queue<int>qq;
bool vis[];
memset(vis,false,sizeof(vis));
qq.push(str);
p1[str].num=;
vis[str]=true;
while(!qq.empty())
{
int m=qq.front();
qq.pop();
for(int j=; j<q[m].size(); j++)
{
int x=q[m][j];
vis[x]=true;
if(p1[x].num==-){
p1[x].num=p1[m].num+;
qq.push(x);
}
}
}
} int main()
{
int t;
scanf("%d",&t);
string s1,s2,s3;
t1=;
int k1,k2,k3;
for(int i=; i<=t; i++)
{
cin>>s1>>s2>>s3;
k1=getnum(s1);
k2=getnum(s2);
k3=getnum(s3);
q[k1].push_back(k2);
q[k1].push_back(k3);
q[k2].push_back(k1);
q[k2].push_back(k3);
q[k3].push_back(k1);
q[k3].push_back(k2);
}
for(int j=; j<t1; j++)
{
p1[j].num=-;
}
string s4="Isenbaev";
int num1;
bool flag=false;
for(int j=; j<t1; j++)
{
if(p1[j].s==s4)
{
flag=true;
num1=j;
break;
}
}
if(flag)
bfs(num1);
sort(p1,p1+t1);
for(int i=; i<t1; i++)
{
if(p1[i].num==-)
{
cout<<p1[i].s<<" "<<"undefined"<<endl;
}
else
cout<<p1[i].s<<" "<<p1[i].num<<endl;
}
return ;
}
ural 1837 Isenbaev's Number的更多相关文章
- ural 1837. Isenbaev's Number bfs
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1837 描述: Isenbaev是国外的一个大牛. 现在有许多人要参加ACM ICPC. ...
- URAL 1837. Isenbaev's Number (map + Dijkstra || BFS)
1837. Isenbaev's Number Time limit: 0.5 second Memory limit: 64 MB Vladislav Isenbaev is a two-time ...
- 1837. Isenbaev's Number(floyd)
1837 被数据结构部分打击的不行了 换地 刷点简单的 图论第一题 floyd水过 #include <iostream> #include<cstdio> #include& ...
- ural 1748 The Most Complex Number 和 丑数
题目:http://acm.timus.ru/problem.aspx?space=1&num=1748 题意:求n范围内约数个数最多的那个数. Roughly speaking, for a ...
- URAL 1748. The Most Complex Number(反素数)
题目链接 题意 :给你一个n,让你找出小于等于n的数中因子个数最多的那个数,并且输出因子个数,如果有多个答案,输出数最小的那个 思路 : 官方题解 : (1)此题最容易想到的是穷举,但是肯定超时. ( ...
- URAL 1748 The Most Complex Number
题目链接:https://vjudge.net/problem/11177 题目大意: 求小于等于 n 的最大反素数. 分析: n <= 10^18,而前20个素数的乘积早超过10^18,因此可 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
随机推荐
- WIndows系统下mysql-noinstall安装配置
环境: Windowsmysql-noinstall-5.0.37-win32.zip 一.下载MySQL http://www.mysql.com/downloads 二.安装过程 1.解压缩mys ...
- Mvc中DropDownList 和DropDownListFor的常用方法
Mvc中DropDownList 和DropDownListFor的常用方法 一.非强类型: Controller:ViewData["AreId"] = from a in rp ...
- IOS学习教程
http://edu.51cto.com/course/course_id-566.html
- jsp if else c标签 总结
JSTL标签使用方法 keyword:JSTL标签.<c:choose>.<c:forEach>.<c:forTokens>.<c:if>.<c: ...
- 设计模式--迪米特法则(Lod/LKP)
迪米特法则:(Law of Demeter, LoD),也称最少知识原则(Least Knowledge Principle, LKP) 理解: 假设两个类不必彼此直接通信,那么这两个类就不 ...
- Thinkpad Edge E440 Ubuntu14.04 无线网卡驱动 解决
http://ubuntuforums.org/showthread.php?t=2190347 正文: Thinkpad Edge E440 安装 Ubuntu12.04 后 无法使用无线网卡, 须 ...
- PHP5.4新特性(转)
PHP5.4正式前两天发布了,之前有看了一些PHP5.4主要特性相关文章,因此在这里小结一下. 其中好几点更新是由Laruence贡献的!本文部分内容也是源自Laruence的博客. 1. Buid- ...
- NYOJ-129 并查集
这个题基本上是并查集稍微一变, 只是加了一些判断条件而已,就是将点合并成树, 最后遍历一下, 统计一下有多少棵树, 如果不是1的话, 肯定不是树,所以,可以根据这个来判断 #include <s ...
- @CacheEvict(value = { "" })
org.springframework.cache.annotation.CacheEvict
- ICSharpCode.SharpZipLib实现压缩解压缩
最近,在项目中经常需要处理压缩和解压缩文件的操作.经过查找,发现了ICSharpCode.SharpZipLib.dll ,这是一个完全由c#编写的Zip, GZip.Tar . BZip2 类库,可 ...