上善若水

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  2 Posts :: 32 Stories :: 2 Comments :: 0 Trackbacks

常用链接

留言簿

我参与的团队

最新随笔

搜索

  •  

积分与排名

  • 积分 - 9751
  • 排名 - 1179

最新评论

阅读排行榜

评论排行榜

Humidex

时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
总提交:69            测试通过:26

描述

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 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.

输出

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.

 

样例输入

T 30 D 15
T 30.0 D 25.0
E

样例输出

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

题目来源

Waterloo July 14, 2007


分析:题中已知那个公式,给其中两个参数求第三个参数。而中间唯一困难的就是求D那个了,不过还好不难推,中间用到了exp()和log()两个函数,头文件math.h。AC了
#include <stdio.h>
#include 
<math.h>
#define max 9999
double totem(double dew,double hum)
{
    
double e=6.11*exp(5417.7530*((1/273.16)-(1/(dew+273.16))));
    
double h=(0.5555)*(e-10.0);
    
return hum-h;
}
double tohum(double t,double d)

    
double e=6.11*exp(5417.7530*((1/273.16)-(1/(d+273.16))));
    
double h=(0.5555)*(e-10.0);
    
return t+h;
}

double todew(double tem,double hum)
{
    
double h=hum-tem;
    
double e=h/0.5555+10.0;
    
return 1/(1/273.16-log(e/6.11)/5417.7530)-273.16;
}

int main()
{
    
double tem,hum,dew;
    
double x,y;
    
char a,b;
    
while(scanf("%c",&a),a!='E')
    {
        getwchar();
        scanf(
"%lf %c %lf",&x,&b,&y);
        getwchar();
        tem
=max;hum=max;dew=max;
        
switch(a)
        {
        
case 'T': tem=x;break;
        
case 'D': dew=x;break;
        
case 'H': hum=x;break;
        }
        
switch(b)
        {
        
case 'T': tem=y;break;
        
case 'D': dew=y;break;
        
case 'H': hum=y;break;
        }
        
if (tem==max)
        {
            tem
=totem(dew,hum);
        }
else if (dew==max)
        {
            dew
=todew(tem,hum);
        }
        
else if (hum==max)
        {
            hum
=tohum(tem,dew);
        }
        printf(
"T %.1lf D %.1lf H %.1lf\n",tem,dew,hum);
    }
}
posted on 2009-12-03 08:58 上善若水 阅读(256) 评论(1)  编辑 收藏 引用

Feedback

# re: Nuaa Acm 1096 Humidex(算术题) 2014-04-14 08:53
1<=i<=1000000约数之和  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理