您的位置:首页 > 其它

ubuntu10.10 重装XP 修复grub

2011-05-07 14:19 519 查看
 

/* THE PROGRAM IS MADE BY PYY */
/*----------------------------------------------------------------------------//
Copyright (c) 2012 panyanyany All rights reserved.

URL   : http://acm.hdu.edu.cn/showproblem.php?pid=1325 Name  : 1325 Is It A Tree?

Date  : Tuesday, April 10, 2012
Time Stage : one hour

Result:
5744703	2012-04-10 16:19:24	Accepted	1325
0MS	612K	1133 B
C++	pyy

Test Data :

Review :
hdu 的数据比poj弱,没有以下两种情况:
0 0
1 1 0 0
答案都是 not a tree。
除此之外要注意的是循环的情况:
1 2 1 3 2 1 0 0 // not a tree
和两棵树的情况:
1 2 3 4 0 0 //not a tree
//----------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>

#include <algorithm>
#include <iostream>
#include <queue>

using namespace std ;

#define MAXN    (1002)

int		set[MAXN];
int		flag;
int		tcase;

void init()
{
int i;
memset(set, -1, sizeof(set));
flag = 0;
}

int find(int x)
{
if (set[x] == -1)
set[x] = x;
if (set[x] == x)
return x;
return set[x] = find(set[x]);
}

int main()
{
int i, j;
int x, y;
tcase = 1;
init();
while (scanf("%d %d", &x, &y) != EOF)
{
if (x == -1 && y == -1)
break;
if (x == 0 && y == 0)
{
printf ("Case %d", tcase++);
if (!flag)
{
j = 0;
for (i = 0; i < MAXN; ++i)
if (set[i] == i)
++j;
if (j > 1)    // not a tree: 1 2 3 4 0 0, a tree: 0 0
flag = 1;
}
if (!flag)
{
printf (" is a tree.\n");
}
else
printf (" is not a tree.\n");
init();
continue;
}
int px = find(x);
int py = find(y);

if (py != y && px != py || x == y || (x != y && px == py))// not a tree: 1 2 1 3 2 1 0 0
{// not a tree: 1 1 0 0
flag = 1;
}
else
set[py] = set[px];
}
return 0;
}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: