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 sosidami at 2008-09-03 14:23:39 on Problem 3684
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
void quick_sort(double *x, int low, int high)
{
	int i, j;
	double t;
	
	if (low < high) /*要排序的元素起止下标,保证小的放在左边,大的放在右边。这里以下标为low的元素为基准点*/
	{
		i = low;
		j = high;
		t = *(x+low); /*暂存基准点的数*/
		
		while (i<j) /*循环扫描*/
		{
			while (i<j && *(x+j)>t) /*在右边的只要比基准点大仍放在右边*/
			{
				j--; /*前移一个位置*/
			}
			
			if (i<j) 
			{
				*(x+i) = *(x+j); /*上面的循环退出:即出现比基准点小的数,替换基准点的数*/
				i++; /*后移一个位置,并以此为基准点*/
			}
			
			while (i<j && *(x+i)<=t) /*在左边的只要小于等于基准点仍放在左边*/
			{
				i++; /*后移一个位置*/
			}
			
			if (i<j)
			{
				*(x+j) = *(x+i); /*上面的循环退出:即出现比基准点大的数,放到右边*/
				j--; /*前移一个位置*/
			}
		}
		
		*(x+i) = t; /*一遍扫描完后,放到适当位置*/
		quick_sort(x,low,i-1);  /*对基准点左边的数再执行快速排序*/
		quick_sort(x,i+1,high);  /*对基准点右边的数再执行快速排序*/
	}
}

int main()
{
    int C;
    cin>>C;
    while(C--)
    {
		int N,H,R,T,i,j,k;
		cin>>N>>H>>R>>T;
		double distance[101];//最后的距离 
		double starttime[101];//开始时间 
		double time[101];//周期 
		double height[101];
		for(i=1;i<=100;i++)
		{
			height[i]=H+2*R/100*(i-1);
			time[i]=2*sqrt(2.0*(H+2*R/100*(i-1))/10);
			starttime[i]=i-1;
			distance[i]=height[i];
		}
		int cishu;
		if(T>N)
		{
			cishu=100;
		}
		else
		{
			cishu=T;
		}
		
		for(i=1;i<=cishu;i++)
		{
			double temp=(T-starttime[i])-(int)((T-starttime[i])/time[i])*time[i]-time[i]/2;
			if(temp>0)
			{
				distance[i]=5*temp*temp;
			}
			else
			{
				distance[i]=height[i]-5*temp*temp;
			}
		}
		quick_sort(distance, 1, 100);
		for(i=1;i<=N;i++)
		{
			printf("%.2f",distance[i]*100);
			cout<<" ";
			
		}
		cout<<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