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 JokerKS at 2010-10-09 18:36:11 on Problem 1442
不就是重复“插几个数,排序,再输出第几小的数”么??
那就把新数放到尾巴上再快排啊……WHY WA?
#include<stdio.h>
#include<stdlib.h>
int n,m,nm[31000],//存下所有数,就是输入数据的第一行
    s[31000],//已经加入序列的数
    p,u[31000];//第i次GET在第几次ADD后,就是输入数据的第二行
int cmp(const void *a,const void *b)
{
    return (*(int *)a-*(int *)b);
}
int main()
{
     int i;
     while(scanf("%d%d",&n,&m)!=EOF)
     {
      for(i=1;i<=n;i++) scanf("%d",&s[i]);
      for(i=1;i<=m;i++) scanf("%d",&u[i]);
      for(i=1,p=1;i<=n;i++)
        {
         nm[i]=s[i];
         if(u[p]==i)
           {
            qsort(nm+1,i,sizeof(int),cmp);
            while(u[p]==i)
               printf("%d\n",nm[p++]);
           }
        }
     }
     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