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

Re:哪位高手看看呀 为什么总是WA

Posted by mcgrady118 at 2008-07-24 00:44:51 on Problem 1862
In Reply To:哪位高手看看呀 为什么总是WA Posted by:00448322 at 2005-04-07 17:13:08
> #include <iostream>
> #include <cstdlib>
> #include <cmath>
> #include <iomanip>
> 
> using namespace std;
> 
> int cmp(const void *a,const void *b)
> {
> 	return -(*(int*)a-*(int*)b);
> }
> 
> void main()
> {
> 	int num[100];
> 	int n;
> 	int i;
> 	double sum;
> 	cin>>n;
> 	cout<<setiosflags(ios::fixed);
> 	while(cin)
> 	{
> 		for(i=0;i<n;i++)
> 			cin>>num[i];
> 		if(n==1)
> 		{	
> 			cout<<setprecision(3)<<double(num[0])<<endl;
> 			continue;
> 		}
> 		qsort(num,n,sizeof(int),cmp);
> 		sum=2*sqrt(double(num[0]*num[1]));
> 		for(i=2;i<n;i++)
> 			sum=2*sqrt(double(sum*num[i]));
> 		cout<<setprecision(3)<<sum<<endl;
> 		cin>>n;
> 	}
> }

#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int cmp(const void *a,const void *b)
{
	return -(*(int*)a-*(int*)b);
}

int main()
{
	int num[100];
	int n;
	int i;
	double sum;
	while(cin>>n)
	{
		for(i=0;i<n;i++)
			cin>>num[i];
		if(n==1)
		{	
			cout<<fixed<<setprecision(3)<<double(num[0])<<endl;
			continue;
		}
		qsort(num,n,sizeof(int),cmp);
		sum=2*sqrt(double(num[0]*num[1]));
		for(i=2;i<n;i++)
			sum=2*sqrt(double(sum*num[i]));
		cout<<fixed<<setprecision(3)<<sum<<endl;
	}
 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