| ||||||||||
| 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 | |||||||||
虽然了,觉得程序还是太繁,帮忙优化下!!虽然是水题,还是花了很长时间,路过帮我看一下,如何把程序更优化~~~
~~~~~~~~~~~
^#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator