求humidex和temperature的时候就是简单的运用他给你的公式,这里要记住exp()函数的功能是求e的x次方。
当求dewpoint ,我们只要二分,并利用humidex和temperature中的任何一个计算另一个值,观察是否相等,因为在【-100,100】区间范围之内,函数是个单调函数,所以可以根据此来二分。
| Time Limit: 1000MS |
| Memory Limit: 65536K |
| Total Submissions: 12382 |
| Accepted: 4597 |
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
T number D number H numberwhere 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<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
#define eps 1e-8
map<char,double> mci;
map<char,bool> jud;
double humi()
{
double e,h;
e=6.11*exp(5417.7530*((1/273.16)-(1/(mci['D']+273.16))));
h=0.5555*(e-10.0);
return mci['T']+h;
}
double temp()
{
double e,h;
e=6.11*exp(5417.7530*((1/273.16)-(1/(mci['D']+273.16))));
h=0.5555*(e-10.0);
return mci['H']-h;
}
double dew()
{
double l=-100,r=100,m;
while(l+eps<r)
{
m=(l+r)/2;
mci['D']=m;
if(mci['H']>humi())
l=m;
else
r=m;
}
return r;
}
int main()
{
char s[5];
mci['D']=mci['H']=mci['T']=0;
while(1)
{
jud['D']=jud['H']=jud['T']=0;
scanf("%s",s);
if(s[0]=='E') break;
scanf("%lf",&mci[s[0]]);
jud[s[0]]=1;
scanf("%s",s);
scanf("%lf",&mci[s[0]]);
jud[s[0]]=1;
if(!jud['D']) mci['D']=dew();
if(!jud['H']) mci['H']=humi();
if(!jud['T']) mci['T']=temp();
printf("T %.1lf D %.1lf H %.1lf\n",mci['T'],mci['D'],mci['H']);
}
return 0;
}
本文介绍了一种用于反映高温高湿环境下人体舒适度的指标——Humidex的计算方法及温度、露点与Humidex之间的相互转换算法。通过使用特定公式和二分查找技巧,可以在给定两个参数的情况下求出第三个未知数。

298

被折叠的 条评论
为什么被折叠?



