NYOJ6喷水装置(一)

//NYOJ6喷水装置(一)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include <algorithm>
using namespace std;
double a[605];
int total = 0;
void greedySelect(double a[], int N);
bool cmp(double a, double b)
{
	return a > b;
}
int main(void)
{
	int m, n;
//	freopen("in.txt", "r", stdin);
	scanf("%d", &m);
	while(m--)
	{
		scanf("%d", &n);
		for(int i = 0; i < n; i++)
		{
			scanf("%lf", &a[i]);
		}
		sort(a, a + n, cmp);//默认升序;
		total = 0;
		greedySelect(a, n);
		printf("%d\n", total);
	}
	return 0;
}
void greedySelect(double a[], int n)
{
	double c = 20;
	for(int i = 0; i < n; i++)	
	{
		if(c > 0)
		{
			c -= 2 * sqrt(a[i] * a[i] - 1);
			total++;
		}
		else
			break;
	}
}

你可能感兴趣的:(NYOJ6喷水装置(一))