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

dashuitiyige

Posted by KatrineYang at 2016-08-19 05:39:03 on Problem 3300 and last updated at 2016-08-19 05:39:38
#include <iostream>
#include <stdio.h>
using namespace std;
void quickSort(double s[], int l, int r)
{
    if (l < r)
    {
        int i = l, j = r;
        double x = s[l];
        while (i < j)
        {
            while(i < j && s[j] >= x)
                j--;
            if(i < j)
                s[i++] = s[j];
            while(i < j && s[i] < x)
                i++;
            if(i < j)
                s[j--] = s[i];
        }
        s[i] = x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
int main() {
	while(1){
		int frontNum, rearNum;
		cin >> frontNum;
		if(frontNum == 0) return 0;
		cin >> rearNum;
		int front[12], rear[12];
		for(int i = 0; i < frontNum; i++){
			cin >> front[i];
		}
		for(int i = 0; i < rearNum; i++){
			cin >> rear[i];
		}
		double rat[111];
		int cnt = 0;
		for(int i = 0; i < frontNum; i++){
			for(int j = 0; j < rearNum; j++){
				rat[cnt] = rear[j]*1.0/front[i];
				cnt++;
			}
		}
		quickSort(rat, 0, cnt-1);
		double spread = 0;
		for(int i = 0; i < cnt-1; i++){
			if(rat[i+1]-rat[i] < 1e-5) continue;
			double tS = rat[i+1]/rat[i];
			if(tS > spread) spread = tS;
		}
		printf("%.2lf\n", spread);
	}
	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