暑假集训(2)第一弹 -----Is It A Tree?(Poj308)
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu
Description
There is exactly one node, called the root, to which no directed edges point.
Every node except the root has exactly one edge pointing to it.
There is a unique sequence of directed edges from the root to each node.
For example, consider the illustrations below, in which nodes are represented by circles and edges are represented by lines with arrowheads. The first two of these are trees, but the last is not.
In this problem you will be given several descriptions of collections of nodes connected by directed edges. For each of these you are to determine if the collection satisfies the definition of a tree or not.
Input
Output
Sample Input
6 8 5 3 5 2 6 4
5 6 0 0 8 1 7 3 6 2 8 9 7 5
7 4 7 8 7 6 0 0 3 8 6 8 6 4
5 3 5 6 5 2 0 0
-1 -1
Sample Output
Case 1 is a tree.
Case 2 is a tree.
Case 3 is not a tree。 问题分析:题目要求判断是否为树,先理清是树的条件,树是一种无向简单连通图
1.无回路和环 也就是说(1,2)(2,1)或者(1,1)或者(1,5)(1,5)这些情况都是不行的。
2.要点与点之间连通,而且注意空树(即无点无边的树)也是树。
#include "cstdio"
struct node
{
int i;
int j;
};
node a[],b[];
int number,time=;
int nbegin()
{
int i=;
time++;
while (scanf ("%d%d",&a[i].i,&a[i].j)&& (a[i].i != - || a[i].j != -))
{
number = i;
if (a[i].i || a[i].j)
i++;
else
return ;
}
return ;
}
void tree()
{
int now,next,q;
node y;
if (a[number].i == && a[number].j == && number == )
{
printf ("Case %d is a tree.\n",time);
return;
}
for (int i=;i<number;i++)
{
for (int k=;k<number;k++)
{
if (a[i].j == a[k].j && i != k)
{
printf("Case %d is not a tree.\n",time);
return;
}
if (a[i].i == a[k].j && a[i].j == a[k].i)
{
printf("Case %d is not a tree.\n",time);
return;
}
}
}
for (int i=;i<number;i++)
{
now=;
next=;
q=;
for (int t=;t<number;t++)
if (a[t].i == a[i].i )
{
b[next++] = a[t];
q++;
}
while (next != now)
{
y = b[now];
now++;
for (int j=;j<number;j++)
if (y.j == a[j].i && y.i != a[j].j)
{
b[next++] = a[j];
q++;
}
}
if (q == number)
{
printf ("Case %d is a tree.\n",time);
return;
}
}
printf("Case %d is not a tree.\n",time);
}
int main()
{
while(nbegin())
tree();
return ;
}
暑假集训(2)第一弹 -----Is It A Tree?(Poj308)的更多相关文章
- 暑假集训(4)第一弹 -----递推(Hdu2039)
题意梗概:fff团团员小A想退团了,不过要退团,他必须绘制出贤者法阵,以证明他有资格不受大fff之灵的监督 并退团,小A他现在要开始收集材料了,但是,他不清楚应该买多少份材料. 虽然你并不想帮他退团, ...
- 暑假集训(1)第一弹 -----士兵队列训练问题(Hdu1276)
Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行一至三报数,凡报 ...
- 暑假集训(5)第一弹——— Super Jumping! Jumping! Jumping!(hdu1087)
题意概括:在上次与娑殚的三次博弈中,你们都取得了胜利.便向娑殚提出要求,借助他的力量,传送到一个安全的地方. 你们的愿望达成了,不过,你和小A似乎失散了. 街上人来人往的特别热闹,每一个人的脸上都洋溢 ...
- 暑假集训(3)第一弹 -----还是畅通工程(hdu1233)
题意梗概:N(n<100)个村子想要富起来,自然就要先修路,不过到底还是没富起来,所以陷入了一个怪圈 :资金不足->修不起路->资金不足...... 为了实现走向全民小康社会,全面实 ...
- 暑假集训(3)第二弹 -----Jungle Roads(Hdu1301)
问题梗概:自从上次某个acmer来设计了拉格瑞圣岛的交通路线后,岛上的酋长就相当苦恼,他发现,虽然这些修好的公路便利了岛上的 交通,并且让拉格瑞圣岛的旅游业更加兴旺,甚至他们还收到了一笔不小的国际资金 ...
- 暑假集训(4)第二弹 -----递推(hdu2254)
题意概括:上次小A在你的帮助下成功炼成贤者法阵的第一部分——三角分隔,现在他准备绘制法阵的第二部分——莫测矩形. 而他又遇到了一个问题,他不知道不同矩形到底有多少个. 秉持帮人帮到底,送佛送到西的基本 ...
- 暑假集训(2)第二弹 ----- The Suspects(POJ1611)
B - The Suspects Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:20000KB ...
- 暑假集训(5)第二弹———湫湫系列故事——减肥记I(hdu4508)
问题描述:舔了舔嘴上的油渍,你陷在身后柔软的靠椅上.在德源大赛中获得优胜的你,迫不及待地赶到“吃到饱”饭店吃到饱.当你 正准备离开时,服务员叫住了你,“先生,您还没有吃完你所点的酒菜.”指着你桌上的一 ...
- 暑假集训(2)第九弹 ----- Points on Cycle(hdu1700)
Points on Cycle Time Limit:1000MS Memory Limit:32768 ...
随机推荐
- Spring-demo1(初学者的尝试,2015.03.19)
项目结构: 源代码如下: package com.bean; public interface Person { public void Speak(); } package com.bean; pu ...
- 学习微信小程序之css13关于盒子外边距的合并
- 安装、配置JDK的步骤
1.配置环境变量,打开我的电脑--属性--高级--环境变量,新建系统变量JAVA_HOME .变量值:jdk的目录,比如d:/java.选择“系统变量”中变量名为“Path”的环境变量双击该变量,把J ...
- Java 解析epub格式电子书,helloWorld程序,附带源程序和相关jar包
秀才坤坤出品 一.epub格式电子书 相关材料和源码均在链接中可以下载:http://pan.baidu.com/s/1bnm8YXT 包括 1.JAVA项目工程test_epub,里面包括了jar包 ...
- 【Heritrix基础教程之1】在Eclipse中配置Heritrix
一.新建项目并将Heritrix源代码导入 1.下载heritrix-1.14.4-src.zip和heritrix-1.14.4.zip两个压缩包,并解压,以后分别简称SRC包和ZIP包: 2.在E ...
- (原创)speex与wav格式音频文件的互相转换
我们的司信项目又有了新的需求,就是要做会议室.然而需求却很纠结,要继续按照原来发语音消息那样的形式来实现这个会议的功能,还要实现语音播放的计时,暂停,语音的拼接,还要绘制频谱图等等. 如果是wav,m ...
- Java基础知识强化之集合框架笔记66:Map集合面试题之HashMap和Hashtable区别(重要)
1. HashMap和Hashtable区别 ? • Hashtable:线程安全,效率低.不允许null键和null值 • HashMap:线程不安全,效率高.允许null键和null值 packa ...
- Beyond REST: How to build a HATEOAS API in Java with Spring MVC, Jersey (JAX-RS) and VRaptor
http://zeroturnaround.com/rebellabs/beyond-rest-how-to-build-a-hateoas-api-in-java-with-spring-mvc-j ...
- Orcle11g用户密码恢复
1.当安装Orcle11g后,很久不用,忘记了用户名和密码.可以通过以下方法重置: 如上图及重置用户sys,system密码为123
- 【转】SharePoint 中实现ReportView
微软的Visual studio提供了ReportViewer控件以及RDLC报表设计工具.下文主要介绍如何在Sharepoint 2010项目开发中使用ReportViewer和RDLC生成项目报表 ...