Grass is Green
Root | |
3719 - Grass is GreenTime 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 1nle10000 <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 1m100000 <tex2html_verbatim_mark>of money this person has, the cost 1g100 <tex2html_verbatim_mark>of a unit amount of grass this person plants, and the cost 1f100 <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\n", cnt);
}
return 0;
}
Grass is Green的更多相关文章
- PHP 5.5 新特性
文章转自:http://wulijun.github.io/2013/07/17/whats-new-in-php-5-5.html http://www.cnblogs.com/yjf512/p/3 ...
- 第 14 章 结构和其他数据形式(enum枚举)
/*----------------------------- enum.c -- 使用枚举类型的值 -----------------------------*/ #include <stdi ...
- 【资料总结】html开发小实例
目 录 第1章 1 HTML的基本标签 1 第2章 25 表格基础 25 第3章 53 表单和框架 53 第4章 77 CSS样式表 77 第5章 104 使用Dreamweaver制作网页 104 ...
- [Tkinter 教程] 布局管理 (Pack Place Grid)
原系列地址: Python Tkinter 简介: 本文讲述如何使用 tkinter 的布局管理 (被称作 layout managers 或 geometry managers). tkinter ...
- PHP 数组使用之道
本文首发于 PHP 数组使用之道,转载请注明出处. 这个教程我将通过一些实用的实例和最佳实践的方式列举出 PHP 中常用的数组函数.每个 PHP 工程师都应该掌握它们的使用方法,以及如何通过组合使用来 ...
- [Tkinter 教程12] 布局管理 (Pack Place Grid)
简介: 本文讲述如何使用 tkinter 的布局管理 (被称作 layout managers 或 geometry managers). tkinter 有三种布局管理方式: pack grid p ...
- hdu----(1849)Rabbit and Grass(简单的尼姆博弈)
Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 分形之概率学下的green tree
今天做的是分形之随机概率,可以和以前做的那个抛色子的做法非常相似,抛色子是用随机点数控制图形,今天做的树叶图形只是用概率的做法去控制图形而已,做法是如出一辙的: //图形界面 package ...
- python 安装nltk,使用(英文分词处理,词干化等)(Green VPN)
安装pip命令之后: sudo pip install -U pyyaml nltk import nltk nltk.download() 等待ing 目前访问不了,故使用Green VPN htt ...
随机推荐
- python 读取blob
for num in range(76802): # if num == 0: # c[num] = imagedata[0:4] # d[num] = struct.unpack('i', c[nu ...
- Windows Forms编程实战学习:第一章 初识Windows Forms
初识Windows Forms 1,用C#编程 using System.Windows.Forms; [assembly: System.Reflection.AssemblyVersion(& ...
- [图算法] 1030. Travel Plan (30)
1030. Travel Plan (30) A traveler's map gives the distances between cities along the highways, toget ...
- linux虚拟机发邮件给163邮件
配置/etc/mail.rc文件 set from=xxxxxxxx@163.com smtp=smtp.163.com set smtp-auth-user=yinhuanyi_cn@163.com ...
- HDU 2164 Rock, Paper, or Scissors?
http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...
- Ubuntu下搭建FTP服务器图解
在Linux中ftp服务器的全名叫 vsftpd,我们需要利用相关命令来开启安装ftp服务器,然后再在vsftpd.conf中进行相关配置,下面我来介绍在Ubuntu中vsftpd安装与配置增加用户的 ...
- 转:pairwise 代码参考
Learning to rank with scikit-learn: the pairwise transform http://fa.bianp.net/blog/2012/learning-to ...
- 51nod1222 最小公倍数计数 莫比乌斯反演 数学
求$\sum_{i = 1}^{n} \sum_{j = 1}^{i} [lcm(i, j) \le n]$因为这样不好求,我们改成求$\sum_{i = 1}^{n} \sum_{j = 1}^{n ...
- 如何用Qt Python创建简单的桌面条形码应用
Qt for Python可以快速跨平台的GUI应用.这篇文章分享下如何结合Dynamsoft Barcode Reader SDK来创建一个简单的读码应用. 安装Qt for Python 官方站点 ...
- Ajax+Js局部刷新
通过 AJAX,JavaScript 可使用 JavaScript 的 XMLHttpRequest 对象来直接与服务器进行通信.通过这个对象, JavaScript 可在不重载页面的情况与 Web ...