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;
    }
    

      

  • 相关阅读:
    价值理论的出发点和落脚点都是人--以人为本
    价值理论是人类决策和行为的标尺
    事实判断和价值判断
    什么是价值理论?---人们认识世界和改造世界的过程可分解为四个基本阶段
    大人只看利弊 小孩才分对错
    为人处世、事实判断和价值判断皆不可少--人类认识客观事物的标尺:对错与利弊
    知行之间--价值与真理--行动的标尺
    事实判断与价值判断之间的桥梁就是人的需要
    10分钟梳理MySQL核心知识点
    postman设置环境变量,实现一套接口根据选择的环境去请求不同的url
  • 原文地址:https://www.cnblogs.com/cszlg/p/3203666.html
Copyright © 2011-2022 走看看