zoukankan      html  css  js  c++  java
  • Grass is Green

    Root Submit Download as PDF Problem Stats

    3719 - Grass is Green

    Time limit: 3.000 seconds

    This year exactly n <tex2html_verbatim_mark>people bought land in Squareville_including you. When someone buys land, then the first thing they do is to plant grass on the land; everyone wants to make sure that their grass is greener than the neighbour's. Depending on the type of grass, planting it has a certain cost. The next thing to do is to build a fence around the land; the cost of the fence depends of the type of the fence (green or white, with or without barbed wire, electric or not, etc.) Everyone has a very particular idea about the type of grass and the type of fence they want. In fact, everyone firstly decided upon the type of grass and fence, and then bought the largest piece of land they could afford (i.e., they could buy the land, the grass, andthe fence). In Squareville, you can buy only square-shaped land, but you can buy any size you want. We assume that everyone plants grass across the whole area of land and everyone builds a fence around the full perimeter, i.e., on all four sides.

    Having a larger garden means that you are more respected in Squareville. Therefore, you would like to know how many of the n <tex2html_verbatim_mark>people will have larger land than you. Your task is to write a program thatcalculates this number.

    Input 

    The input contains several blocks of test cases. Each case begins with a line containing an integer 1$ le$nle10000 <tex2html_verbatim_mark>, the number of people buying land and a real number 0 < c < 100 <tex2html_verbatim_mark>, the cost of a unit area of land. The next n <tex2html_verbatim_mark>lines describe the n <tex2html_verbatim_mark>people; the first of these lines describes you. Each line contains three real numbers: the amount 1$ le$m$ le$100000 <tex2html_verbatim_mark>of money this person has, the cost 1$ le$g$ le$100 <tex2html_verbatim_mark>of a unit amount of grass this person plants, and the cost 1$ le$f$ le$100 <tex2html_verbatim_mark>of a unit length of fence this person builds.

    The input is terminated by a block with n = c = 0 <tex2html_verbatim_mark>.

    Output 

    For each test case, you have to output a single integer: how many people have larger land than you. Thus, if you have the largest land, then output `0'; if you have the smallest land, then output n - 1 <tex2html_verbatim_mark>.

    Sample Input 

    5 1
    32.0 5.0 1.0
    16.0 1.0 1.0
    63.0 2.0 3.0
    68.0 10.0 3.0
    88.0 1.0 10.0
    0 0
    

    Sample Output 

    1

    解一元二次方程即可
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <queue>
    #include <vector>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    const double eps = 10e-8;
    const int MAXN = 10005;
    double m, c, g, f;
    int n;
    double p[MAXN];
    
    int main()
    {
        while(scanf("%d %lf", &n, &c) && n && c)
        {
            for(int i = 0; i < n; i++)
            {
                scanf("%lf %lf %lf", &m, &g, &f);
                p[i] = 8.0 * (-f + sqrt(f * f + (g + c) * m / 4.0)) / (g + c);
            }
            int cnt = 0;
            for(int i = 1; i < n; i++)
            {
                if(fabs(p[i] - p[0]) < eps) continue;
                if(p[i] > p[0]) cnt++;
            }
            printf("%d
    ", cnt);
        }
        return 0;
    }
    

      

  • 相关阅读:
    遂宁2017届零诊16题(仅想说明网传答案的不正确)
    当参变分离遇见洛必达
    高考数学九大超纲内容(1)wffc
    给王志红老师构造的函数,想说明搜题软件的解答过程的不严谨!
    记住路径名
    php返回文件路径
    两个字符串合并为一个字符串的各种方法
    global作用域
    二进制字符串的比较
    var_dump — 打印变量的相关信息
  • 原文地址:https://www.cnblogs.com/cszlg/p/3203666.html
Copyright © 2011-2022 走看看