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

why is it wrong?

Posted by woaixiyuan at 2008-04-05 17:07:30 on Problem 2437
#include<stdio.h>
#include<stdlib.h>

int cmp(const void *a,const void *b)
  {
    return *(long*)a-*(long*)b;
  }
  
int main()
  {
    int i,L,m,n,p;
    long sum,p1=0,p2=0;
    long a[20001],d[10001];

    scanf("%d%d",&n,&L);
    for(i=0;i<n;i++)
    {
        scanf("%ld%ld",&a[2*i],&a[2*i+1]);
    }
    
   qsort(a,2*n,sizeof(long),cmp);
    
    for(i=0;i<n;i++)
    {
        d[i]=a[2*i+1]-a[2*i];
        if(d[i]%L==0)
           {  p1+=d[i]/L;  }
        else
           {
              m=(d[i]/L+1)*L-d[i];
              p=a[2*i+1]+m;
              if(p>a[2*i+2])
              {
                  a[2*i+2]=p;
              }
              p2+=d[i]/L+1;
           }
    }
    sum=p1+p2;
    printf("%ld\n",sum);
    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