poj 3299 Humidex

简介:

注:标准输入下,double一定要用   %lf   输入,输出可以是   %f   也可以是   %lf


其实就是纯粹的数学公式推导,然后就是格式的控制(本人认为题目的难点在此,虽然题目不难,O(∩_∩)O哈哈~),再就是精度问题

对于输入的格式控制,因为有字符输入,建议用s%弄,不然总是考虑空格也不方便。。。开始用单个字符 (“%c”,ch) 一直输出不对,后来单步调试才发现是输了一个空格进去,进入了不同的循环。


看别人的结题报告,貌似用cin》可以不用管空格,可以直接cin>>ch;

而且输出控制里面有  cout<<setprecision(1)<<fixed<<"T "<<t<<" D "<<d<<" H "<<h<<endl;


一次AC的代码:

#include <stdio.h>
#include <math.h>

#define MAXN 1000

int main()
{
	char ch[2];
	double t,d,h;

	int i;
	while(1)
	{
		t=d=h=MAXN;		//都在-100~100之间,这个是看哪个没有输入的

		for(i=0;i<2;i++)
		{
			scanf("%s",ch);

			if(ch[0]=='E')
				return 0;

			else if(ch[0]=='T')
				scanf("%lf",&t);
			else if(ch[0]=='D')
				scanf("%lf",&d);
			else if(ch[0]=='H')
				scanf("%lf",&h);
		}
		//test		
		/*if(t!=MAXN)
			printf("temperature = %f\n",t);
		if(d!=MAXN)
			printf("dewpoint = %f\n",d);
		if(h!=MAXN)
			printf("humidex = %f\n",h);

		printf("%f\n",t);
		printf("%f\n",d);
		printf("%f\n",h);*/




		if(h==MAXN)  
            h=t+0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10);  
        else if(t==MAXN)  
            t=h-0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10);  
        else if(d==MAXN)  
            d=1/((1/273.16)-((log((((h-t)/0.5555)+10.0)/6.11))/5417.7530))-273.16;

		printf("T %.1lf D %.1lf H %.1lf\n",t,d,h);
	}

	return 0;
}


相关文章
POJ 2487 Stamps
POJ 2487 Stamps
86 0
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
820 0
poj 2299 求逆序数
http://poj.org/problem?id=2299 #include using namespace std; int aa[500010],bb[500010]; long long s=0; void merge(int l,int m,int r) { ...
769 0
poj 1455
Description n participants of > sit around the table. Each minute one pair of neighbors can change their places.
600 0
|
算法 机器人 编译器
POJ-2632
#include int main() { int k,a,b,n,m,i,j,num,rep,rect[100][100],robot[100][3]; int flag; char c; for(scanf("%d...
883 0
|
机器学习/深度学习 Windows