3299 Humidex

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 + hh = (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

  水题,对我来说最大的坎就是看不懂题了。

 1 #include<iostream>
 2 #include<math.h>
 3 #include<stdio.h>
 4 using namespace std;
 5 int main()
 6 {
 7     double dewpoint,temperature,humidex;
 8     char FC;
 9     while(true)
10     {
11         dewpoint=200;temperature=200;humidex=200;
12         for(int i=0;i<2;i++)
13         {
14             cin>>FC;
15             if(FC == ‘E‘)
16                 return 0;
17             else if(FC == ‘T‘)
18                 cin>>temperature;
19             else if(FC == ‘D‘)
20                 cin>>dewpoint;
21             else if(FC == ‘H‘)
22                 cin>>humidex;
23         }
24         if(humidex==200)
25         {
26             double e = 6.11 * pow(2.718281828,(5417.7530*((1/273.16)-(1/(dewpoint+273.16)))));
27             double h = 0.5555*(e-10.0);
28             humidex = temperature + h;
29         }
30         else if(temperature==200)
31         {
32             double e = 6.11 * pow(2.718281828,(5417.7530*((1/273.16)-(1/(dewpoint+273.16)))));
33             double h = 0.5555*(e-10.0);
34             temperature = humidex - h;
35         }
36         else{
37             double h = humidex - temperature;
38             double e = h/0.5555+10.0;
39             dewpoint = 1/((1/273.16)-log(e/6.11)/5417.7530)-273.16;
40         }
41
42         printf("T %.1f D %.1f H %.1f\n",temperature,dewpoint,humidex);
43     }
44     return 0;
45 }

复习一下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](向离开零的方向取整)
举例:

 1 #include<stdio.h>
 2 #include<math.h>
 3 main()
 4 {
 5     float x,y;
 6     x=74.12;
 7     y=6.4;
 8     printf("74.12/6.4: %f\n",fmod(x,y));
 9     x=74.12;
10     y=-6.4;
11     printf("74.12/(-6.4): %f\n",fmod(x,y));
12     return 0;
13 }

居然有道题目是这样的: 求 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应大于等于零。

原文地址:https://www.cnblogs.com/yxh-amysear/p/8391267.html

时间: 2024-10-04 22:56:50

3299 Humidex的相关文章

POJ 3299 Humidex 难度:0

题目链接:http://poj.org/problem?id=3299 #include <iostream> #include <iomanip> using namespace std; double exp(double x){ double ans=1; double td=1; for(int i=1;i<120;i++){ td=td*x/i; ans+=td; } return ans; } const double ine= 2.718281828 ; dou

POJ - 3299 Humidex

题意:已知两数,根据公式求第三个数. 分析: 1..lfG++编译不过的C++可能编译过. 2.输出.lf改成.f后G++可编译过. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #include<iomanip> #incl

POJ 3299 Humidex(简单题)

[题意简述]:就是什么温度,湿度--,之间的转换.. [分析]:公式已给出了. // 252k 0Ms /* 其中exp表示的是求e的x次幂 解法就直接根据题目中的公式解决就好!! */ #include<iostream> #include<iomanip> #include<cmath> using namespace std; int main() { double t,d,h; char alpha; while(1) { t = d = h = 101; fo

Humidex POJ - 3299 (数学)

题目大意 给定你三个变量中的两个输出剩下的那一个 题解 没有什么,就是把公式推出来即可,完全的数学题 代码 #include <iostream> #include <cmath> #include <cstdio> using namespace std; int main() { /*ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);*/ char c; while(cin>>c) { double t=1

F - Humidex(1.4.2)

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Adapted from Wikipedia, the free encyclopedia The humidex is a measurement used by Canadian meteorologists to reflect the combined effect of heat a

[3299]poj第一题

妈蛋,边听浮夸边撸代码简直醉了,高音飙死我算了,之后找了几个以前喜欢的轻音乐都乱七八糟,妈蛋,(╯‵□′)╯︵┻━┻ 1.int main return 0 2.math.h exp() log() 3.while(scanf("%c",&a),a!='E') 我的思路: 枚举六种情况,六次输出,妈蛋(╯‵□′)╯︵┻━┻一看姐就是有逻辑的人(╯‵□′)╯︵┻━┻ 1 #include<stdio.h> 2 #include<math.h> 3 #inc

poj3299 Humidex

Humidex Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17719   Accepted: 6420 Description Adapted from Wikipedia, the free encyclopedia The humidex is a measurement used by Canadian meteorologists to reflect the combined effect of heat

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

3299: [USACO2011 Open]Corn Maze玉米迷宫 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 137  Solved: 59[Submit][Status][Discuss] Description 今年秋天,约翰带着奶牛们去玩玉米迷宫.迷宫可分成NxM个格子,有些格子种了玉 米,种宥玉米的格子无法通行. 迷宫的四条边界上都是种了玉米的格子,其屮只有一个格子 没种,那就是出口. 在这个迷宫里,有一些神奇的传送点6每个传送点

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

就一个最短路,并且边长都是1,所以每个点只搜一次. 1 /************************************************************** 2 Problem: 3299 3 User: MT_Chan 4 Language: C++ 5 Result: Accepted 6 Time:72 ms 7 Memory:2420 kb 8 ***********************************************************