| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
很遗憾地说,都通过了,还是RA!!(附代码,求指教)In Reply To:注意~!~!~!需要注意的数据 Posted by:xuhanqiu at 2006-08-18 09:48:42 #include <stdio.h>
#include <string.h>
/*我想用一个类似于端口插入的方法来解决这道题*/
/*每个点都有前后两个端口,可连接用 0 表示 已连接用 1 表示*/
int map[2000][2];
int main ()
{
int m,n;
int max = 0;
int point = 0;
int count = 0;
while (scanf ("%d %d",&m,&n) != EOF)
{
if (m == -1 && n == -1)
{
break;
}
if (m == 0 && n == 0)
{
count++;
/*排除森林的情况*/
for (int i = 1;i < max;i++)
{
if (map[i][1] == 0 && map[i + 1][0] == 0)
{
point = 1;
break;
}
}
if (point == 1)
printf ("Case %d is not a tree.\n",count);
else
printf ("Case %d is a tree.\n",count);
for (int i = 0;i < max + 1;i++)
{
map[i][0] = 0;
map[i][1] = 0;
}
point = 0;
max = 0;
continue;
}
/*排除插入同一个点左端口的情况*/
if (map[n][0] == 1)
{
point = 1;
}
/*排除一个点已经有右端口牵出,插入左端口的情况*/
else if (map[m][0] == 1 && map[n][1] == 1)
{
point = 1;
}
/*排除一个点左右端口自我连接的情况*/
if(m == n)
{
point = 1;
}
else
{
map[n][0] = 1;
map[m][1] = 1;
}
if (max < m)
max = m;
if (max < n)
max = n;
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator