POJ 2555

题意:t2摄氏度的冰m2克,扔进t1摄氏度的m1克水中,不考虑外界条件,求最终状态。

题解:临界点为0摄氏度,分四种情况讨论,即等于0摄氏度两种,其余两种。先求出将水完全结成冰需要放出的热量和将冰化成水需要吸收的热量,两两比较,判断化冰还是结冰。然后看将水或冰变成0摄氏度的所贡献的热量是否足以使另一个变成自己,如果是,直接热量相减把两者都当成0摄氏度的某样东西加温或者降温即可,否则,也是相减然后看这温度能使多少冰化成水或者水结成冰。

View Code
 1 #include<cstdio>

 2 #include<cstring>

 3 #include<algorithm>

 4 using namespace std;

 5 const double eps=1e-8;

 6 int main()

 7 {

 8     double q1,q2,m1,t1,m2,t2,p1,p2;

 9     while(scanf("%lf%lf%lf%lf",&m1,&m2,&t1,&t2))

10     {

11         if(m1==0&&m2==0&&t1==0&&t2==0)

12             break;

13         p1=4.19*t1*m1;

14         p2=-2.09*t2*m2;

15         q1=p1+335.0*m1;

16         q2=p2+335*m2;

17         if(q1>q2)

18         {

19             if(q2<p1-eps)

20             {

21                 p1-=q2;

22                 m1+=m2;

23                 t1=p1/m1/4.19;

24                 printf("0.0 g of ice and %.1lf g of water at %.1lf C\n",m1,t1);

25             }

26             else

27             {

28                 p1-=p2;

29                 double m=p1/335.0;

30                 m1+=m;

31                 m2-=m;

32                 printf("%.1lf g of ice and %.1lf g of water at 0.0 C\n",m2,m1);

33             }

34         }

35         else

36         {

37             if(q1<p2-eps)

38             {

39                 p2-=q1;

40                 m2+=m1;

41                 t2=-p2/m2/2.09;

42                 printf("%.1lf g of ice and 0.0 g of water at %.1lf C\n",m2,t2);

43             }

44             else

45             {

46                 p2-=p1;

47                 double m=p2/335.0;

48                 m2+=m;

49                 m1-=m;

50                 printf("%.1lf g of ice and %.1lf g of water at 0.0 C\n",m2,m1);

51             }

52         }

53     }

54     return 0;

55 }

你可能感兴趣的:(poj)