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

为什么是runtime error?

Posted by zhenjie at 2010-02-11 23:55:02 on Problem 1928
我建立的是结构体链表,
#include<iostream>
#include<math.h>
using namespace std;
struct node
{
	int num;
	int line;
	int column;
	node *next;
};
int main()
{
	int n,M,N,K,i,j,a,total,time;
	cin>>n;
	while(n--)
	{
		cin>>M>>N>>K;
		node head,*p,*q;
		head.next=NULL;
		for(i=1;i<=M;i++)
		{
			for(j=1;j<=N;j++)
			{
				cin>>a;
				if(a>0)
				{
					p=&head;
					while(p->next)  //将非0结点插入链表中
					{
						if(p->next->num>a)
							p=p->next;
						else
							break;
					}
					q=(node *)malloc(sizeof(node));
					q->next=p->next;p->next=q;
					q->line=i;q->column=j;q->num=a;
				}
			}
		}
		p=head.next;time=p->line+1;total=p->num;//计算最大数
		while(time+p->line<=K)
		{
			time+=abs(p->next->line-p->line)+abs(p->next->column-p->column)+1;
			total+=p->next->num;
			p=p->next;
		}
		total=total-p->num;
		cout<<total<<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