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 ...
随机推荐
- 第三周pspo过程文档
团队协作: 日期/任务 听课 编写程序 阅读相关书籍 日总计 周一 110 60 ...
- SGU 199 Beautiful People 二维最长递增子序列
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20885 题意: 求二维最长严格递增子序列. 题解: O(n^2) ...
- HDU 5179 beautiful number 数位dp
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- 转 从红帽、GitHub和Docker看开源商业模式的进阶
从红帽.GitHub和Docker看开源商业模式的进阶 发表于2014-12-16 10:26| 7594次阅读| 来源http://stratechery.com/| 0 条评论| 作者Ben Th ...
- Python——cmd调用(os.system阻塞处理)(多条命令执行)
os.system(返回值为0,1,2)方法 0:成功 1:失败 2:错误 os.system默认阻塞当前程序执行,在cmd命令前加入start可不阻塞当前程序执行. 例如: import os os ...
- python基础(一)简单入门
一.第一个python程序 1.交互式编程 直接在命令行里面输入python即可进入python交互式命令行,linux下一样: 在 python 提示符中输入以下文本信息,然后按 Enter 键查看 ...
- 对Excle的行和列进行检查 单元格类型转换代码 ;
对Excle的行和列进行检查 转换代码 : ** * 导入信息 */ @Override public List<Object> add(HttpServletRequest reque ...
- Mysql 学习之 SQL的执行顺序
mysql的json查询: 1.一条普通的SQL SELEC ...
- js中如何获取页面的Url,域名和端口号
有时候通过获取上个页面的Url来做一个跳转,获取域名防止非正常访问 获取上一个页面的一个URL,这个URL一般做一个页面的跳转 window.location.href <script>w ...