文章标题
2015-06-03 12:34
465 查看
**1009 : Are the towns connected by roads?**
描述
The Emergency Measures Organization for an unnamed state wishes to know quickly when a hurricane strikes which counties in the state still have roads connecting all the towns of the county together. You must write a program to determine this.
输入
On the first line there is a number indicating the number of counties (no more than 10). Following that, there is data for each of the counties. For each county, the first line contains the name of the county followed by the number specifying the number of towns (no more than 10) in the county. Each subsequent line contains the names of two towns that are connected by a road. A blank line indicates that all other roads in the county have been washed out by the hurricane. You may assume that the names consist of a single word, that is, that the names do not contain any white space.
输出
for each county, in the order that the counties were input, write out one line stating either:
County (insert name) is connected.
or
County (insert name) is disconnected.
样例输入
2
One 3
First Second
Second First
Two 2
Third Fourth
样例输出
County One is disconnected.
County Two is connected.
题目的意思很简单,就是要你判断这个城市里面的所有的城镇是否可以联通、自己感觉坑的是,输入是以回车结束,所以要自己写这个输入的函数。
简单并查集:
include
include
include
using namespace std;char name1[110][110];
int zhong,father[20],rank[20];
int Find(int a)
{
while(a!=father[a])
{
father[a]=father[father[a]];
a=father[a];
}
return a;
}
void Union(int x,int y)
{
if(x==y)return;
if(rank[x]>rank[y])
father[y]=x,rank[x]+=rank[y];
else
{
father[x]=y;
rank[y]+=rank[x];
}
}
void read()
{
char s[100],s1[100],s2[100];
int len=0,k=0;
for(int i=0;i<=20;i++)
father[i]=i,rank[i]=1;
while(1)
{
char c;
c=getchar();
if(c==’ ‘)s1[len]=’\0’,k++,len=0;
else if(c==’\n’&&k%2==0)return;
else if(c==’\n’)s2[len]=’\0’,k++,len=0;
else if(k%2==0)s1[len++]=c;
else s2[len++]=c;/**/
if(k%2==0&&len==0)
{
int f=0,wei1,wei2;
for(int i=0;i
相关文章推荐
- TZC 1537 除法表达式 gcd
- 小数化分数
- CodeIgniter_2 路由中定义伪静态 直接映射到相关的控制器
- ON DUPLICATE KEY UPDATE
- Ewebeditor最新漏洞及漏洞大全
- 1002: [FJOI2007]轮状病毒
- C#开发微信门户及应用-使用地理位置扩展相关应用
- 疯狂Java学习笔记(70)-----------挚爱Java
- 《推拿》—— 读后总结
- 混淆 - 笔记
- R High-Level
- HDU 4283 You Are the One(区间DP)
- BZOJ 1602: [Usaco2008 Oct]牧场行走( 最短路 )
- 新修改了EMA的计算方法,合并线性回归率的计算。和通达信的结果一模一样
- simclist库使用初体验
- 机器学习算法-K-means聚类
- Python使用minidom读写xml的方法
- 这就是搜索引擎--读书笔记五--索引的建立与更新
- BZOJ3339 Rmq Problem
- 操作系统中的虚拟内存技术及其实现代码