重做題目6 噴水裝置

     已AC代碼:

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
bool compare(double x, double y)
{
    return x*x>y*y;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n, cont=0;
        double len=0;
        scanf("%d", &n);
        double a[n];
        for(int i=0; i<n; i++)
            scanf("%lf", &a[i]);
        sort(a, a+n, compare);
        for(int i=0; ; i++)
        {
            if(len>=20)
                break;
            else
            {
                len += 2*sqrt(a[i]*a[i]-1.0);
                cont++;
            }
        }
        printf("%d\n", cont);
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章