poj3299 Humidex(water)

来源:互联网 发布:sql注入的防御 编辑:程序博客网 时间:2024/05/29 17:09
Humidex
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 20368Accepted: 7350

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 15T 30.0 D 25.0E

Sample Output

T 30.0 D 15.0 H 34.0T 30.0 D 25.0 H 42.3
一开始求d的时候,二分,结果丢精度了。无限WA,需要自己推导公式,看来还是不能偷懒。
#include<iostream>using namespace std;#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<stdlib.h>#include<vector>#include<queue>#include<deque>#include<map>#include<set>#include<time.h>#define pi(x) printf("%d",(x));#define pin(x) printf("%d\n",(x));#define si(x) scanf("%d",&(x))#define sii(x,y) scanf("d",&(x),&(y))#define s3(x,y,z) scanf("d%d",&(x),&(y),&(z))#define rep(x,y,z) for(int (x)=(y);(x)<(z);++(x))#define dep(x,y,z) for(int (x)=(y)-1;(x)>=(z);--(x))#define sl(x) scanf("%lld",&(x))#define read int Tcase;scanf("%d",&Tcase);while(Tcase--)#define cls(x,y) memset((x),(y),sizeof((x)));#define cls0(x) memset((x),0,sizeof((x)));#define max3(value_a,value_b,value_c) max(max(value_a,value_b),value_c)#define GT(x) (x)=clock();typedef long long LL;typedef unsigned long long ULL;const int maxint=((~((unsigned)(0)))>>1);const LL maxll=((~((unsigned long long)(0)))>>1);const int inf=0x3f3f3f3f;const double PI=acos(-1.0);const int maxn=1e3+5;const double eps=1e-9;//int top,head[maxn];//struct note {//    int to,next;//} a[maxn];////void ADD(int u,int v) {//    a[top].next=head[u];//    a[top].to=v;//    head[u]=top++;//}/**humidex = temperature + hh = (0.5555)¡Á (e - 10.0)e = 6.11 ¡Á exp [5417.7530 ¡Á ((1/273.16) -(1/(dewpoint+273.16)))]*/int main() {#ifdef tangge    clock_t tSTART,tEND,t3;    GT(tSTART);#endif // tangge    double t,d,h,hs;    char in;    while(scanf("%c",&in)) {        if(in=='E')break;        t=-10000.0,h=-10000.0,d=-10000.0,hs=-10000.00;        double fl;        getchar();//        cout<<"in="<<in<<endl;        scanf("%lf",&fl);        if(in=='T') {            t=fl;        } else if(in=='D') {            d=fl;        } else if(in=='H') {            h=fl;        }//        cout<<"t="<<t<<" "<<"h="<<h<<" d="<<d<<endl;        getchar();        scanf("%c",&in);//        cout<<"in="<<in<<endl;        scanf("%lf",&fl);        if(in=='T') {            t=fl;        } else if(in=='D') {            d=fl;        } else if(in=='H') {            h=fl;        }        /*        humidex = temperature + hs        hs = (0.5555)¡Á (e - 10.0)        e = 6.11 ¡Á exp [5417.7530 ¡Á ((1/273.16) -(1/(dewpoint+273.16)))]        */        if(fabs(d-(-10000.00))<=eps) {            hs=(h-t);            double es=(hs/0.5555)+10.00;            es/=6.11;            es=log(es);            es/=5417.75300;            es=(1.00/273.1600)-es;            d=(1.00/es)-273.16;//        d=1/((1/273.16)-((log((((h-t)/0.5555)+10.0)/6.11))/5417.7530))-273.16;          } else if(fabs(t-(-10000.00))<=eps) {            double op=6.11* exp (5417.7530 * ((1.00/273.16) -(1.00/(d+273.16))));            hs=(0.5555)*(op - 10.0);            t=h-hs;        } else if(fabs(h-(-10000.00))<=eps) {            double op=6.11* exp (5417.7530 * ((1.00/273.16) -(1.00/(d+273.16))));            hs=(0.5555)*(op - 10.0);            h=t+hs;        }getchar();        printf("T %.1lf D %.1lf H %.1lf\n",t,d,h);    }#ifdef tangge    GT(tEND);    printf("%.8lf\n",(tEND-tSTART)/1000.0);#endif // tangge    return 0;}
0 0
原创粉丝点击