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

集合上面两位的优点,235ms

Posted by 0712105003 at 2009-12-08 16:34:29 on Problem 1423
In Reply To:Re:700多ms过的 用公式可以0ms飘过 那样就更水了 Posted by:980616701 at 2009-05-31 09:26:48
#include<stdio.h>
#include<stdlib.h>
//#include<math.h>
typedef struct
{
    int value;
    int ans;
    int s;    
}node;
int cmp(const void *a,const void *b)
{
    node *p=(node*)a;
    node *q=(node *)b;
    if((p->value)>(q->value))return 1;
    else if((p->value)<=(q->value))return -1;
   // else if(p->s<q->s)return 0;
    //else return 1;
}
int cmp2(const void *a,const void *b)
{
    node *p=(node*)a;
    node *q=(node *)b;
    if(p->s>q->s)return 1;
     return -1;
}
int main()
{
    int c;
    double ans=1.0;
    int bit=0;
    int i=0,j;
   // freopen("datain1.txt","r",stdin);
//    freopen("dataout.txt","w",stdout);
    scanf("%d",&c);
    node *n=(node *)malloc(sizeof(node)*(c+1));
    n[0].value=0;
    for(i=1;i<=c;i++)
    {
        scanf("%d",&n[i].value);
        n[i].s=i;
        n[i].ans=0;
    }
    qsort((void*)(n+1),c,sizeof(n[0]),cmp);
  //   for(i=0;i<=c;i++)
  //         printf("%d ",n[i].value);
     for( i=1,j=n[i-1].value;i<=c&&j<=n[i].value;)
     {
         j++;
         if(j>n[i].value)
         {
             n[i].ans=bit;
             j=n[i].value;
             i++;
            // continue;
         }
         else
         {
         ans*=j;
          if(ans<10){;}
          else	if(ans<100){ans/=10;bit+=1;;}
          else	if(ans<1000){ans/=100;bit+=2;;}
          else	if(ans<10000){ans/=1000;bit+=3;;}
          else	if(ans<100000){ans/=10000;bit+=4;;}
          else	if(ans<1000000){ans/=100000;bit+=5;;}
          else	if(ans<10000000){ans/=1000000;bit+=6;;}
          else	if(ans<100000000){ans/=10000000;bit+=7;;}
         }
      }
     qsort(n+1,c,sizeof(n[0]),cmp2);
      for(i=1;i<=c;i++)
           printf("%d\n",n[i].ans+1);


}


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