POJ 3299 Humidex 水题

23 篇文章 1 订阅

三个数,T表示温度 temperature,D表示露点 dewpoint,H表示湿润指数 humidex
三个数的关系:

1已知T和D求H
H=T+h H = T + h
h=0.5555(e10.0) h = 0.5555 ∗ ( e − 10.0 )
e=6.11exp[5417.75301273.161D+273.16] e = 6.11 ∗ e x p [ 5417.7530 ∗ 1 273.16 − 1 D + 273.16 ]
2已知H和D求T
T=Hh T = H − h
h=0.5555(e10.0) h = 0.5555 ∗ ( e − 10.0 )
$e=6.11*exp[5417.7530*\frac{1}{273.16}-\frac{1}{D+273.16}]¥
3已知T和H求D
h=HT h = H − T
e=h0.5555temp e = h 0.5555 − t e m p
D=11273.16ln(e6.11)5417.7350273.16 D = 1 1 273.16 − l n ( e 6.11 ) 5417.7350 − 273.16

其中1是已经给出的,2和3需要自己根据1去推出,然后就是针对输入的两个数,去求出另外一个数就可以

代码如下:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
double t_and_d_to_h(double temperature, double dewpoint)
{
    double e = 6.11*exp(5417.7530*(1 / 273.16 - 1 / (dewpoint + 273.16)));
    double h = 0.5555*(e - 10.0);
    double humidex = temperature + h;
    return humidex;
}

double h_and_d_to_t(double humidex, double dewpoint)
{
    double e = 6.11*exp(5417.7530*(1 / 273.16 - 1 / (dewpoint + 273.16)));
    double h = 0.5555*(e - 10.0);
    double temperature = humidex - h;
    return temperature;
}

double t_and_h_to_d(double temperature, double humidex)
{
    double h = humidex - temperature;
    double e = h / 0.5555 + 10.0;
    double dewpoint = 1 / (1 / 273.16 - (log(e / 6.11) / 5417.7530)) - 273.16;
    return dewpoint;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    char A[3], B[3];
    double a, b, ans;
    while (scanf("%s %lf %s %lf", A, &a, B, &b) != EOF)
    {
        if (A[0] == 'E')
        {
            break;
        }
        if (A[0] == 'T'&&B[0] == 'D')
        {
            ans = t_and_d_to_h(a, b);
            printf("T %.1lf D %.1lf H %.1lf\n", a, b, ans);
        }
        if (A[0] == 'H'&&B[0] == 'D')
        {
            ans = h_and_d_to_t(a, b);
            printf("T %.1lf D %.1lf H %.1lf\n", ans, b, a);
        }
        if (A[0] == 'T'&&B[0] == 'H')
        {
            ans = t_and_h_to_d(a, b);
            printf("T %.1lf D %.1lf H %.1lf\n", a, ans, b);
        }
        if (A[0] == 'D'&&B[0] == 'T')
        {
            ans = t_and_d_to_h(b, a);
            printf("T %.1lf D %.1lf H %.1lf\n", b, a, ans);
        }
        if (A[0] == 'D'&&B[0] == 'H')
        {
            ans = h_and_d_to_t(b, a);
            printf("T %.1lf D %.1lf H %.1lf\n", ans, a, b);
        }
        if (A[0] == 'H'&&B[0] == 'T')
        {
            ans = t_and_h_to_d(b, a);
            printf("T %.1lf D %.1lf H %.1lf\n", b, ans, a);
        }
        //printf("%.1lf\n", ans);
    }
    //printf("end\n");
    //while (1);
    return 0;
}

这个用C++提交是AC的,但是如果用G++提交,需要将printf("T %.1f D %.1f H %.1f\n", a, b, ans);%.1lf换为%.1f,因为double类型在G++中需要用%f输出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值