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

郁闷,,,用高精度做的,,,

Posted by simon_cqdx at 2007-12-03 11:44:57 on Problem 2924
#include<iostream.h>
main()
{int n,i,j,a,b,d,e,t,v,r,k[100],p[20],q[100];
 bool f;
 cin>>n;
 for (i=1;i<=n;i++)
  {cin>>a>>b;
   d=a+b;e=b-a+1;
   if (d%2==0) d/=2;
   else e/=2;
   f=false;
   t=0;v=0;
   if (d<0) {f=true;d*=-1;}
   else if (d==0) {cout<<"Scenario #"<<i<<':'<<endl<<0<<endl;if (i<n) cout<<endl;continue;}
   for (j=0;j<=99;j++) q[j]=0;
   while (d>0)
   {t++;k[t]=d%10;d/=10;
   }
   while (e>0)
   {v++;p[v]=e%10;e/=10;
   }
   for (j=1;j<=t;j++)
     for (r=1;r<=v;r++)
       {q[j+r-1]+=k[j]*p[r];
       q[j+r]+=q[j+r-1]/10;
       q[j+r-1]%=10;
       }
   t+=v-1;
   while (q[t+1]>0) {t++;q[t+1]+=q[t]/10;q[t]%=10;}
 cout<<"Scenario #"<<i<<':'<<endl;
 if (f) cout<<'-';
 for (j=t;j>=1;j--)
  cout<<q[j];
  cout<<endl;
 if (i<n) cout<<endl;
}
}

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