Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA了两天了啊

Posted by skyencc at 2011-03-08 18:15:23 on Problem 2568 and last updated at 2011-03-08 18:44:08
什么情况啊?
一直通不过,空行的情况考虑了啊,哪位高手给看看啊!!!
#include <iostream>
#include <fstream>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

#define MAX_VNODE_NUM 60

typedef struct ArcNode
{
	int v;
	ArcNode *next;
} ArcNode;

typedef struct VNode
{
	ArcNode * fstarc;
} VNode;

typedef struct ALGraph
{
	VNode vertices[MAX_VNODE_NUM];
	int arcnum, vexnum;
} ALGraph;

//在图的v1节点中插入一条从v1到v2的边
void insert(ALGraph *g, int v1, int v2)
{
	ArcNode *p = new ArcNode();
	p->next = NULL;
	p->v = v2;
	if(g->vertices[v1].fstarc==NULL)
		g->vertices[v1].fstarc = p;
	else
	{
		ArcNode *q = g->vertices[v1].fstarc;
		if(v2<q->v)
		{
			p->next = q;
			g->vertices[v1].fstarc = p;
		}
		else
		{
			ArcNode *prev = q; q = q->next;
			while(q && q->v<v2)
			{
				prev = q; q = q->next;
			}
			p->next = q; prev->next = p;
		}
	}
}

void traverse(ALGraph *g, int k, bool *is_visited)
{
	is_visited[k] = true;
	ArcNode *p = g->vertices[k].fstarc;
	cout<<"("<<k;
	while(p)
	{
		if(!is_visited[p->v])
		{
			cout<<" ";
			traverse(g, p->v, is_visited);
		}
		p = p->next;
	}
	cout<<")";
}

int main()
{
	string s;
	int *edge_count = new int[MAX_VNODE_NUM];
	bool *is_visited = new bool[MAX_VNODE_NUM];
	queue<int> que;
	ALGraph *g = new ALGraph();

	int i=0, j=0, v=0; 
	ArcNode *p;
	while(!cin.eof())
	{
		getline(cin, s);
		if(s.compare("")==0) {cout<<"(1)"<<endl; continue;}

		stringstream ss(s);
		memset(edge_count, 0, sizeof(int)*MAX_VNODE_NUM);
		memset(is_visited, false, sizeof(bool)*MAX_VNODE_NUM);
		for(int i=0; i<MAX_VNODE_NUM; i++)
			g->vertices[i].fstarc = NULL;

		while(ss>>v) 
		{
			edge_count[v]++;
			que.push(v);
		}
		g->vexnum = que.back();
		
                //构建图
		for(j=1; j<g->vexnum; j++)
		{
			for(i=1; i<=g->vexnum; i++)
			{
				if(edge_count[i]==0)
				{
					edge_count[i] = -1;				
					edge_count[que.front()]--;

					insert(g, i, que.front());
					insert(g, que.front(), i);
					que.pop();
					break;
				}
			}
		}
                //遍历图
		traverse(g, 1, is_visited);
		cout<<endl;
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator