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 |
为什么是runtime error?我建立的是结构体链表, #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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator