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

800k^2的计算量吗??

Posted by ziliang at 2007-09-21 16:08:33 on Problem 2786
In Reply To:time limited!晕!大家有什么更好的算法呀 Posted by:a024014 at 2006-11-11 22:38:20
> #include <stdio.h>
> #include <string.h>
> #include <iostream> 
> #include <algorithm> 
> using namespace std; 
> typedef struct
> {
>     int w;
>     int d;
> }Order;
> Order a[800001];
> short flag[800001];
> bool cmp(Order x,Order y)
> {
>     return x.d<y.d;
> }
> int main(void)
> {
>     int num,i,j,k;
>     int counter,pos,max;
>     while(scanf("%d",&num)!=EOF)
>     {
>         for(i=0;i<num;i++)
>             scanf("%d%d",&a[i].w,&a[i].d);
>         memset(flag,0,sizeof(flag));
>         counter=num;
>         pos=0;
>         sort(a,a+num,cmp);
>         for(i=0;i<num;i++)
>         {
>             pos+=a[i].w;
>             if(pos>a[i].d)
>             {
>                 max=0;
>                 for(j=0;j<=i;j++)
>                     if((!flag[j])&&a[j].w>max)
>                     {
>                         max=a[j].w;
>                         k=j;
>                     }
>                 flag[k]=1;
>                 pos-=max;
>                 counter--;
>             }
>         }
>         printf("%d\n",counter);
>     }
>     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