pku3299
2007-08-07 09:30
218 查看
简单的数学一元方程求解问题,分情况讨论即可.
题目中给出的是3个等式,最好将其中可以直接计算的部分算出,并且将其合并为一个方程,这样不仅可以减少运行中用于相同运算的时间,还有利于更好的求解.
不过,该题的一个关键点还是输入输出的处理.在使用cout.precision()时才发现它不是设定小数位数的,而是设定有效数字的位数,纠正一个错误.
Source:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
void TD();
void TH();
void DH();
//humidex = temperature -5.555+ 3.394105*exp[19.833625-5417.753/(dewpoint+273.16)]
//
//h =3.394105*e - 5.555
//e = exp [19.833625 - 5417.753/(dewpoint+273.16)]
double t,d,h,e;
int main()
{
char ch;
while(1)
{
ch=getchar();
switch(ch)
{
case 'T':cin>>t;
getchar();
ch=getchar();
switch(ch)
{
case 'D':cin>>d;
TD();
break;
case 'H':cin>>h;
TH();
break;
}
getchar();
break;
case 'D':cin>>d;
getchar();
ch=getchar();
switch(ch)
{
case 'T':cin>>t;
TD();
break;
case 'H':cin>>h;
DH();
break;
}
getchar();
break;
case 'H':cin>>h;
getchar();
ch=getchar();
switch(ch)
{
case 'T':cin>>t;
TH();
break;
case 'D':cin>>d;
DH();
break;
}
getchar();
break;
case 'E':return 0;
}
cout.precision(3);
cout.setf(ios::showpoint);
cout.fill('0');
//cout.width(4);
cout<<"T "<<setw(4)<<t<<" D "<<setw(4)<<d<<" H "<<setw(4)<<h<<endl;
}
return 0;
}
void TD()
{
e=3.394105*exp(19.833625-5417.75/(d+273.16));
h=t+e-5.555;
}
void TH()
{
d=5417.753/(19.833625-log((h-t+5.555)/3.394105))-273.16;
}
void DH()
{
e=3.394105*exp(19.833625-5417.75/(d+273.16));
t=h+5.555-e;
}
题目中给出的是3个等式,最好将其中可以直接计算的部分算出,并且将其合并为一个方程,这样不仅可以减少运行中用于相同运算的时间,还有利于更好的求解.
不过,该题的一个关键点还是输入输出的处理.在使用cout.precision()时才发现它不是设定小数位数的,而是设定有效数字的位数,纠正一个错误.
Source:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
void TD();
void TH();
void DH();
//humidex = temperature -5.555+ 3.394105*exp[19.833625-5417.753/(dewpoint+273.16)]
//
//h =3.394105*e - 5.555
//e = exp [19.833625 - 5417.753/(dewpoint+273.16)]
double t,d,h,e;
int main()
{
char ch;
while(1)
{
ch=getchar();
switch(ch)
{
case 'T':cin>>t;
getchar();
ch=getchar();
switch(ch)
{
case 'D':cin>>d;
TD();
break;
case 'H':cin>>h;
TH();
break;
}
getchar();
break;
case 'D':cin>>d;
getchar();
ch=getchar();
switch(ch)
{
case 'T':cin>>t;
TD();
break;
case 'H':cin>>h;
DH();
break;
}
getchar();
break;
case 'H':cin>>h;
getchar();
ch=getchar();
switch(ch)
{
case 'T':cin>>t;
TH();
break;
case 'D':cin>>d;
DH();
break;
}
getchar();
break;
case 'E':return 0;
}
cout.precision(3);
cout.setf(ios::showpoint);
cout.fill('0');
//cout.width(4);
cout<<"T "<<setw(4)<<t<<" D "<<setw(4)<<d<<" H "<<setw(4)<<h<<endl;
}
return 0;
}
void TD()
{
e=3.394105*exp(19.833625-5417.75/(d+273.16));
h=t+e-5.555;
}
void TH()
{
d=5417.753/(19.833625-log((h-t+5.555)/3.394105))-273.16;
}
void DH()
{
e=3.394105*exp(19.833625-5417.75/(d+273.16));
t=h+5.555-e;
}
相关文章推荐
- PKU 3299 Humidex
- 假金币问题-PKUacm1029-ACM
- DFS PKU 1979
- 【BZOJ】3299: [USACO2011 Open]Corn Maze玉米迷宫(bfs)
- 3299: [USACO2011 Open]Corn Maze玉米迷宫 (BFS)
- PKU 4047 - Garden(线段树 + 区间修改)
- 【分块】【线段树】bzoj3212 Pku3468 A Simple Problem with Integers
- PKU Judge Online 安装指南
- Poj 3299 Humidex
- PKU 2084 Game of Connections
- 【并查集】PKU-1182 食物链
- PKU 1562 Oil Deposit
- 北大PKU在线测试1005
- PKU C++程序设计实习 学习笔记2 继承与派生
- PKU Campus 2015 E:Transformation
- PKU 1679 The Unique MST(解题报告)
- POJ 3299 Humidex(水~)
- PKU 2406:Power Strings 【KMP】
- BZOJ1895: Pku3580 supermemo
- pku 1061