poj 2555 Drink, on Ice

Drink, on Ice
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1283 Accepted: 777

Description

A good drink is always served on ice. That said, the amount of ice is what makes the difference. If it is too much, the drink will be well cooled, however, this is a bit of fraud as there could be less ice (and more Vodka for example). On the other hand, if there is too little ice the drink is warm which is unacceptable. You are to help the bartender, of course neither with mixing nor drinking, but with calculating the expected outcome of such mixtures.
To make things easier, we assume that pure water is mixed with ice in a closed system, i.e., there is no problem with the outside temperature or the warming of the bottle, etc. Therefore, after a some time has passed, the system may be regarded as balanced (there is no further change in temperature and no more melting or freezing). Your job is to calculate the final temperature of this balanced system and the amount of ice and water in this equilibrium state.
As you know from physics, it takes 4.19 Joule to heat one gram of water one Kelvin, whereas it takes 2.09 Joule if it is ice. We define the capacities cw = 4.19 J/(g*K) and ci = 2.09 J/(g*K). Melting one gram of ice takes 335 Joule, where the temperature remains constant at zero. We define the constant em = 335 J/g. The total thermal energy of the ice and the water before the experiment is equal to the thermal energy of the final mixture.
The figure below shows the energy of one gram of ice, ice-water-mixture, or water, where the temperature is measured relative to -30 degrees Celsius. The jump at 0 degrees represents the melting of ice to water. The amount of energy gained is proportional to the amount of ice already melted.

Input

The input contains several test cases. Each test case consists of four real numbers mw, mi, tw, ti. The mass of water mw and the mass of ice mi are both non-negative, given in grams, and mw + mi > 0. The water temperature tw and the ice temperature ti follow, both given in degrees Celsius, and you may assume that -30 < ti <= 0 <= tw < 100. The last test case is followed by four zeroes.

Output

For each test case output the amount of ice and water in grams and the final temperature of the mixture in degrees Celsius. All numbers must be rounded to one digit. Adhere to the sample output for the exact format to use.

Sample Input

100 20 50 -10
100 22 0  0
100 35 25 -10.5
10  90 25 -28
0 0 0 0

Sample Output

0.0 g of ice and 120.0 g of water at 27.5 C
22.0 g of ice and 100.0 g of water at 0.0 C
6.0 g of ice and 129.0 g of water at 0.0 C
100.0 g of ice and 0.0 g of water at -4.2 C
#include<iostream>
using namespace std;
double mw,mi,tw,ti,resi,resw,rest;
int main()
{
while(1)
{
scanf("%lf %lf %lf %lf",&mw,&mi,&tw,&ti);
ti=-ti;
if( mw+mi+tw+ti==0.0 )
break;
if( mw*tw*4.19>mi*ti*2.09 )
{
if( mw*tw*4.19>mi*ti*2.09+335.*mi )
{
resi = 0;
resw = mw+mi;
rest = (mw*tw*4.19-mi*ti*2.09-335.*mi)/((mi+mw)*4.19);
}
else
{
resi = mi - (mw*tw*4.19-mi*ti*2.09)/335.;
resw = mw + (mw*tw*4.19-mi*ti*2.09)/335.;
rest = 0;
}
}
else
{
if( mi*ti*2.09>mw*tw*4.19+335.*mw )
{
resi = mw+mi;
resw = 0;
rest = -(mi*ti*2.09-mw*tw*4.19-335.*mw)/((mw+mi)*2.09);
}
else
{
resi = mi + (mi*ti*2.09-mw*tw*4.19)/335.;
resw = mw - (mi*ti*2.09-mw*tw*4.19)/335.;
rest = 0;
}
}
printf("%.1f g of ice and %.1f g of water at %.1f C\n",resi,resw,rest);
}
return 0;
}

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/22/2258587.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值