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

虽然了,觉得程序还是太繁,帮忙优化下!!

Posted by lzl000 at 2009-07-27 17:30:33 on Problem 1978
虽然是水题,还是花了很长时间,路过帮我看一下,如何把程序更优化~~~
~~~~~~~~~~~


^#include"stdio.h"
^#include"stdlib.h"
^int main()
^{int n, r;
^  while((scanf("%d%d",&n,&r)&&(n||r))!=0)
^  {  int *a, *b;
^     int i, j, p, c,p1;
^	 if(n<1||n>50||r<1||r>50)  break;
^	 a=(int*)malloc((n+1)*sizeof(int));
^	 b=(int*)malloc((n+1)*sizeof(int));
^   for(i=1;i<=n;i++)
^	a[i]=n+1-i;
^   for(i=1;i<=r;i++)
^	{
^	  scanf("%d",&p);
^	  getchar();
^	  scanf("%d",&c);
^	  if(p+c>n+1)  exit(0);
^
^	  for(j=1;j<=p-1;j++)
^	    b[j]=a[j];
^	  for(j=1;j<=c;j++)  
^	    a[j]=a[p1++];
^     for(j=1;j<=p-1;j++)
^        a[++c]=b[j];
^	   	
^	}
^	printf("%d\n",a[1]);
^  }
^  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