暑假集训(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 ...
随机推荐
- 除去重复记录distinct
在查询数据库时候,可以使用distinct关键字过滤重复记录 例如 SELECT distinct ShiftID FROM [AdventureWorks].[HumanResources].[Em ...
- Storm系列(七)架构分析之Scheduler-调度器[DefaultScheduler]
Storm默认的任务调度器.实现如下: 1 (defn –prepare [this conf]) 2 (defn –schedule [this ^Topologies topologies ^ ...
- HW5.24
import java.util.Calendar; public class Solution { public static void main(String[] args) { System.o ...
- Codeforces Round #341 (Div. 2) ABCDE
http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇 ...
- Shell的那些事儿
日常工作中,哪种语言对你的帮助最大?我觉得非Shell莫属.最早接触Shell应该是在大学的时候,如做Linux文件系统裁减会用到一些命令,如find, tar, xargs, cp等等,并把它们通过 ...
- 问题-delphi在某电脑(win7)上是界面超乱 DPL
问题现象:本机运行正常,但是在WIN7或个别的XP上,界面显示控件大小不一,界面超乱 问题原因:可以百度“delphi dpi”或者“delphi 控件自适应分辨率” 问题处理:将窗体的Scaled设 ...
- c++ template笔记
1. 数组 template <typename T, int N> void array_print(T (&arr)[N]) { for(int i = 0; i < N ...
- 【JAVA - 基础】之Annotation注解浅析
注解在JAVA中,尤其是一些ORM框架(如Hibernate等)中是比较常用的一种机制. 注解是JAVA 1.5之后引入的新功能,正确来说是反射的一部分,没有反射,注解也就无法正常使用.注解可以理解成 ...
- Java - 错误: "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1"
错误: "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1" 本文地址: http://blog.csdn.n ...
- [HTML5] Accessible Icon Buttons
Icon buttons are very common in web applications, yet they often have accessibility problems. Learn ...