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 knuthocean at 2005-03-04 15:01:15 on Problem 1005
我写的程序精度很高,但不知道错在哪儿呀,郁闷!!!!!
#include <stdio.h>
#include <iostream.h>
#include <math.h>

int multiply(int* a,int m,int* b,int n,int* c)
{
	int i,j,k,r,t;
	for(i=0;i<m;i++) c[i]=0;
	for(j=0;j<n;j++){
		r=0;
		for(k=0;k<m;k++){
			t=a[k]*b[j]+c[k+j]+r;
			c[k+j]=t%10;
			r=t/10;
		}
		c[j+m]=r;
	}
	int len=m+n;
	while((len>1)&&(c[len-1]==0)) len--;
	return len;
}
int sum(int a[],int b[],int lena,int lenb)
{
	int len=(lena>=lenb)?lena:lenb;
	int i;
	a[len]=0;
	if(len==lena){
    	
        for(i=lenb;i<lena;i++)
			b[i]=0;
        }
    else
        for(i=lena;i<lenb;i++)
			a[i]=0;
    for(i=0;i<len;i++){
        a[i]=a[i]+b[i];
        if(a[i]>=10){ a[i]-=10;a[i+1]++;}
        }
	if(a[len]>0) len++;
    return len;
}

void main()
{
int n;
int i;
int k;
int x[400],y[400],z[800];
int z1[800],z2[800];
int result[820];
int pi[15]={3,1,4,1,5,9,2,6,5,3,5,8,9,7,9};

for(i=0;i<7;i++){
		int swap=pi[i];
		pi[i]=pi[14-i];
		pi[14-i]=swap;
	}

cin>>n;
long *record=new long[n+1];
for(k=0;k<n;k++){
	
	char c;
	
	int xpoints=0,ypoints=0;
	int lenx=0,leny=0;
	

	i=0;

	int flag=0;
	while(1){
		scanf("%c",&c);
		if(c==' ') break;
		if(c!='.'){
			if(flag) xpoints++;
			x[i]=c-'0';
			i++;
			lenx++;
		}
		else
			flag=1;
		
	}
	if((x[0]==((int)'-' - (int)'0'))||((x[0]==(int)'+' - (int)'0'))){
		lenx--;
		for(i=0;i<lenx;i++)
			x[i]=x[i+1];
	}
	flag=0;i=0;
	while(1){
		scanf("%c",&c);
        
		if(c=='\n') break;
		
		if(c!='.'){
			if(flag) ypoints++;
			y[i]=c-'0';
			i++;
			leny++;
		}
		else flag=1;
	}



	i=0;
    if(y[i]==((int)' ' - (int)'0')){
		while((y[i]==((int)' ' - (int)'0'))&&(i<(leny-1)))  i++;
		leny-=i;
		for(int index=0;index<leny;index++)
			y[index]=y[index+i];
	}
	i=0;
	if(y[i]==(int)'+' - (int)'0'){
		leny--;
		for(i=0;i<leny;i++)
			y[i]=y[i+1];
	}
			
	
	while((lenx>1)&&(x[lenx-1]==0)&&(xpoints>0)) {lenx--;xpoints--;}
	while((leny>1)&&(y[leny-1]==0)&&(ypoints>0)) {leny--;ypoints--;}
	
   int temp;
   for(i=0;i<lenx/2;i++){
         temp=x[i];
         x[i]=x[lenx-1-i];
         x[lenx-1-i]=temp;
		 }
   for(i=0;i<leny/2;i++){
	     temp=y[i];
		 y[i]=y[leny-1-i];
		 y[leny-1-i]=temp;
		 }
  

   
	
	
	int lenz1=multiply(x,lenx,x,lenx,z1);

	int lenz2=multiply(y,leny,y,leny,z2);


	xpoints+=xpoints;ypoints+=ypoints;

    int num;
	if(xpoints>ypoints){
		num=xpoints-ypoints;
		for(i=lenz2-1;i>=0;i--)
			z2[i+num]=z2[i];
		for(i=0;i<num;i++)
			z2[i]=0;
		lenz2+=num;
		
		
	}
	else if(xpoints<ypoints){
		num=ypoints-xpoints;
		for(i=lenz1-1;i>=0;i--)
			z1[i+num]=z1[i];
		for(i=0;i<num;i++)
			z1[i]=0;
		lenz1+=num;
		
	}


	int lenz=sum(z1,z2,lenz1,lenz2);
	for(i=0;i<lenz;i++)
		z[i]=z1[i];

	
	
	int length=multiply(z,lenz,pi,15,result);
	int points=14;
	points+=(xpoints>=ypoints)?xpoints:ypoints;

	
	long l=0;
	for(i=length-1;i>=points+2;i--)
		l=l*10+(long)result[i];

	record[k]=l+1;
}

   for(k=0;k<n;k++)
		cout<<"Property "<<k+1<<": This property will begin eroding in year "<<record[k]<<"."<<endl;
	cout<<"END OF OUTPUT."<<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