Humidex
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 23219   Accepted: 8264

Description

Adapted from Wikipedia, the free encyclopedia

The humidex is a measurement used by Canadian meteorologists to reflect the combined effect of heat and humidity. It differs from the heat index used in the United States in using dew point rather than relative humidity.

When the temperature is 30°C (86°F) and the dew point is 15°C (59°F), the humidex is 34 (note that humidex is a dimensionless number, but that the number indicates an approximate temperature in C). If the temperature remains 30°C and the dew point rises to 25°C (77°F), the humidex rises to 42.3.

The humidex tends to be higher than the U.S. heat index at equal temperature and relative humidity.

The current formula for determining the humidex was developed by J.M. Masterton and F.A. Richardson of Canada's Atmospheric Environment Service in 1979.

According to the Meteorological Service of Canada, a humidex of at least 40 causes "great discomfort" and above 45 is "dangerous." When the humidex hits 54, heat stroke is imminent.

The record humidex in Canada occurred on June 20, 1953, when Windsor, Ontario hit 52.1. (The residents of Windsor would not have known this at the time, since the humidex had yet to be invented.) More recently, the humidex reached 50 on July 14, 1995 in both Windsor and Toronto.

The humidex formula is as follows:

humidex = temperature + h
h = (0.5555)× (e - 10.0)
e = 6.11 × exp [5417.7530 × ((1/273.16) - (1/(dewpoint+273.16)))]

where exp(x) is 2.718281828 raised to the exponent x.

While humidex is just a number, radio announcers often announce it as if it were the temperature, e.g. "It's 47 degrees out there ... [pause] .. with the humidex,". Sometimes weather reports give the temperature and dewpoint, or the temperature and humidex, but rarely do they report all three measurements. Write a program that, given any two of the measurements, will calculate the third.

You may assume that for all inputs, the temperature, dewpoint, and humidex are all between -100°C and 100°C.

Input

Input will consist of a number of lines. Each line except the last will consist of four items separated by spaces: a letter, a number, a second letter, and a second number. Each letter specifies the meaning of the number that follows it, and will be either T, indicating temperature, D, indicating dewpoint, or H, indicating humidex. The last line of input will consist of the single letter E.

Output

For each line of input except the last, produce one line of output. Each line of output should have the form:

T number D number H number

where the three numbers are replaced with the temperature, dewpoint, and humidex. Each value should be expressed rounded to the nearest tenth of a degree, with exactly one digit after the decimal point. All temperatures are in degrees celsius.

Sample Input

T 30 D 15
T 30.0 D 25.0
E

Sample Output

T 30.0 D 15.0 H 34.0
T 30.0 D 25.0 H 42.3

Source

 
  水题,对我来说最大的坎就是看不懂题了。
 #include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main()
{
double dewpoint,temperature,humidex;
char FC;
while(true)
{
dewpoint=;temperature=;humidex=;
for(int i=;i<;i++)
{
cin>>FC;
if(FC == 'E')
return ;
else if(FC == 'T')
cin>>temperature;
else if(FC == 'D')
cin>>dewpoint;
else if(FC == 'H')
cin>>humidex;
}
if(humidex==)
{
double e = 6.11 * pow(2.718281828,(5417.7530*((/273.16)-(/(dewpoint+273.16)))));
double h = 0.5555*(e-10.0);
humidex = temperature + h;
}
else if(temperature==)
{
double e = 6.11 * pow(2.718281828,(5417.7530*((/273.16)-(/(dewpoint+273.16)))));
double h = 0.5555*(e-10.0);
temperature = humidex - h;
}
else{
double h = humidex - temperature;
double e = h/0.5555+10.0;
dewpoint = /((/273.16)-log(e/6.11)/5417.7530)-273.16;
} printf("T %.1f D %.1f H %.1f\n",temperature,dewpoint,humidex);
}
return ;
}

复习一下math.h库:

abs
原型:extern int abs(int x);
用法:#include <math.h>
功能:求整数x的绝对值
说明:计算|x|, 当x不为负时返回x,否则返回-x

fabs
原型:extern float fabs(float x);
用法:#include <math.h>
功能:求浮点数x的绝对值
说明:计算|x|, 当x不为负时返回x,否则返回-x

ceil
原型:extern float ceil(float x);
用法:#include <math.h>
功能:求不小于x的最小整数
说明:返回x的上限,如74.12的上限为75,-74.12的上限为-74。返回值为float类型。

exp
原型:extern float exp(float x);
用法:#include <math.h>
功能:求e的x次幂
说明:e=2.718281828...

floor
原型:extern float floor(float x);
用法:#include <math.h>
功能:求不大于x的最达整数
说明:返回x的下限,如74.12的下限为74,-74.12的下限为-75。返回值为float类型。

fmod
原型:extern float fmod(float x, float y);
用法:#include <math.h>
功能:计算x/y的余数
说明:返回x-n*y,符号同y。n=[x/y](向离开零的方向取整)
举例:

 #include<stdio.h>
#include<math.h>
main()
{
float x,y;
x=74.12;
y=6.4;
printf("74.12/6.4: %f\n",fmod(x,y));
x=74.12;
y=-6.4;
printf("74.12/(-6.4): %f\n",fmod(x,y));
return ;
}

居然有道题目是这样的: 求 100 % 8的 优化解法。我们知道:

8刚好是2的3次方

所以 100 % 8 == 100 – math.floor(100 / 8) * 8 == 100 -  ((100 >> 3) << 3)

log
原型:extern float log(float x);
用法:#include <math.h>
功能:计算x的自然对数。
说明:x的值应大于零。

log10
原型:extern float log10(float x);
用法:#include <math.h>
功能:计算x的常用对数。
说明:x的值应大于零。

pow10
原型:extern float pow10(float x);
用法:#include <math.h>
功能:计算10的x次幂。
说明:相当于pow(10.0,x)。

pow
原型:extern float pow(float x, float y);
用法:#include <math.h>
功能:计算x的y次幂。
说明:x应大于零,返回幂指数的结果。

sqrt
原型:extern float sqrt(float x);
用法:#include <math.h>
功能:计算x的平方根。
说明:x应大于等于零。

3299 Humidex的更多相关文章

  1. POJ 3299 Humidex 难度:0

    题目链接:http://poj.org/problem?id=3299 #include <iostream> #include <iomanip> using namespa ...

  2. poj 3299 Humidex

    直接套公式就可以,可我套公式第一遍都错了,英语差的孩子伤不起(┬_┬) #include <iostream> #include <cmath> #include <io ...

  3. POJ 3299 Humidex(简单的问题)

    [简要题意]:什么是温度,湿度--,之间的转换.. [分析]:式已被赋予. // 252k 0Ms /* 当中exp表示的是求e的x次幂 解法就直接依据题目中的公式解决就好!! */ #include ...

  4. 算法之路 level 01 problem set

    2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...

  5. 每日一水 POJ8道水题

    1. POJ 3299 Humidex 链接: http://poj.org/problem?id=3299 这道题是已知H,D,T三者的运算关系,然后告诉你其中两个.求另一个. #include&l ...

  6. Humidex POJ - 3299 (数学)

    题目大意 给定你三个变量中的两个输出剩下的那一个 题解 没有什么,就是把公式推出来即可,完全的数学题 代码 #include <iostream> #include <cmath&g ...

  7. poj3299 - Humidex

    2017-08-31 19:08:25 writer:pprp 水题: 没有技术含量hhh 但是,还是花了很长时间,以后水题也是很有必要练习的 /* @theme:poj 3299 @writer:p ...

  8. 【bzoj 3299】 [USACO2011 Open]Corn Maze玉米迷宫(最短路)

    就一个最短路,并且边长都是1,所以每个点只搜一次. /************************************************************** Problem: 3 ...

  9. 3299: [USACO2011 Open]Corn Maze玉米迷宫

    3299: [USACO2011 Open]Corn Maze玉米迷宫 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 137  Solved: 59[ ...

随机推荐

  1. BPM软件_K2再度入选Gartner iBPMS MQ挑战者象限_全球领先的工作流引擎

    在Gartner 于1月最新发布的2018 iBPMS MQ报告中,K2再度入选“挑战者”象限,相较去年,K2在“前瞻性”方面有了显著提升. Gartner对该标准的定义为:供应商对市场具有清晰认识, ...

  2. 常见python面试题-手写代码系列

    1.如何反向迭代一个序列 #如果是一个list,最快的方法使用reversetempList = [1,2,3,4]tempList.reverse()for x in tempList:    pr ...

  3. 如何创建一个前端 React 组件并发布到 NPM

    首先npm文档摆在这里: https://www.npmjs.cn/ 参考组件 https://github.com/rakuten-rex/rex-dropdownhttps://www.npmjs ...

  4. mock.js学习之路一(Vue中使用)

    1.安装mockjs 2.配置mockjs在开发环境中启用,生产环境中禁用 3.创建mock文件夹,以及mock数据文件 4.在main.js中引入与否 5.页面获取数据 testMock(){ th ...

  5. 【leetcode】561. Array Partition I

    原题: Given an array of 2n integers, your task is to group these integers into n pairs of integer, say ...

  6. jumpserver跳板机docker安装小小趟坑

    最近日常运维的时候发现每次登陆服务器都要打开终端目录连接对应的服务器,闲暇的时候还好,运维任务很重的时候才发现这样的玩法很傻,浪费时间且一点儿都跟不上潮流,然后打开githup开始搞起来.docker ...

  7. davinci 删除路线站点关系

    删除路线站点关系 DELETE FROM tb_station_info_draw WHERE id in (SELECT stationId FROM tb_road_station_relatio ...

  8. Matlab[linux]安装问题

    OS : Arch Linux 桌面:Gnome X11 软件是从网上下载的iso文件,对文件挂载或者使用解压软件解压,我个人更喜欢挂载,解压有点麻烦(我比较懒) 软件:matlab(R2016) 开 ...

  9. ECMAScript 6 入门——ES6 声明变量的六种方法

    ES6 声明变量的六种方法 ES5 只有两种声明变量的方法:var命令和function命令.ES6 除了添加let和const命令,后面章节还会提到,另外两种声明变量的方法:import命令和cla ...

  10. bzoj1497: [NOI2006]最大获利(最小割)

    传送门 第一眼看去:好难 第二眼:不就是个裸的最大权闭合子图么…… 我们从源点向所有用户连边,容量为收益,用户向自己的中转站连边,容量为INF,中转站向汇点连边,容量为费用 那么总收益-最小割就是答案 ...