码迷,mamicode.com
首页 > 其他好文 > 详细

poj3299

时间:2014-05-26 01:57:13      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   c   code   

                                                                                                     Humidex
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 15974   Accepted: 5811

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

Waterloo Local Contest, 2007.7.14
bubuko.com,布布扣
 1 #include <iostream>
 2 #include<cmath>
 3 #include<cstdio>
 4 
 5 
 6 using namespace std;
 7 
 8 int main()
 9 {
10     char x1,x2;
11     float a,b;
12     while(scanf("%c",&x1)!=EOF&&x1!=E)
13     {
14         float temp,hum,dew;
15         temp = hum = dew =-99999.0;
16         scanf("%f %c %f",&a,&x2,&b);
17         getchar();
18         if(x1==T) temp = a;
19         if(x1==D) dew = a;
20         if(x1==H) hum = a;
21         if(x2==T) temp=b;
22         if(x2==D) dew = b;
23         if(x2==H) hum = b;
24         //已知tem,dew求hum
25         if(hum==-99999.0)
26         {
27             float m = 5417.7530*((1/273.16)-(1/(dew+273.16)));
28             float e = 6.11*exp(m);
29             float h = 0.5555*(e-10.0);
30             hum = temp + h;
31         }
32         else if(temp==-99999.0)
33         {
34             float m = 5417.7530*((1/273.16)-(1/(dew+273.16)));
35             float e = 6.11*exp(m);
36             float h = 0.5555*(e-10.0);
37             temp = hum - h;
38         }
39         else if(dew==-99999.0)
40         {
41             float h = hum - temp;
42             float e =h/(0.5555) + 10.0;
43             float t = log(e/6.11);
44             float m = 1/273.16 - t/5417.7530;
45             dew = 1/m-273.16;
46         }
47         printf("T %.1f D %.1f H %.1f\n",temp,dew,hum);
48 
49     }
50     return 0;
51 }
bubuko.com,布布扣

这题就是数学题吧,其实最重要的处理是在已知hum,temp求dew的时候,因为我们需要化简一个公式,看到一本书上用的是二分法来在-100和100中是循环dew,接着算出每个结果与已经给出的hum和temp匹配,但是实际上没必要,我们可以反推出dew对应的计算机公式就行了。本题有些陷阱,不需要四舍五入。

poj3299,布布扣,bubuko.com

poj3299

标签:des   style   class   blog   c   code   

原文地址:http://www.cnblogs.com/jhldreams/p/3749591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!