URAL 1823. Ideal Gas(數學啊 )

來源:互聯網
上載者:User

標籤:ural   數學   

題目連結:http://acm.timus.ru/problem.aspx?space=1&num=1823


1823. Ideal GasTime limit: 0.5 second
Memory limit: 64 MB
Many of you know the universal method of solving simple physics problems: you have to find in a textbook an identity in which you know the values of all the quantities except for one, substitute the numbers into this identity, and calculate the unknown quantity.This problem is even easier. You know right away that the identity needed for its solution is the Clapeyron–Mendeleev equation for the state of an ideal gas. This equation relates the pressure of an ideal gas p, the amount of substance n, the volume occupied by the gas V, and the temperature T. Given three of these quantities, you have to find the fourth quantity. Note that the temperature of a gas and the volume occupied by it must always be positive.InputEach of the three input lines has the form “X = value”, where X is the symbol for a physical quantity and value is a nonnegative integer not exceeding 1000. The three lines specify the values of three different quantities. Pressure is specified in pascals, amount of substance in moles, volume in cubic meters, and temperature in kelvins. It is guaranteed that the temperature and volume are positive. The universal gas constant R should be taken equal to 8.314 J / (mol · K).OutputIf the input data are inconsistent, output the only line “error”. If the value of X can be determined uniquely, output it in the format “X = value” with an accuracy of 10?3. If it is impossible to uniquely determine the value of X, output the only line “undefined”.Sample
input output
p = 1n = 1V = 1
T = 0.120279
NotesRecall that Pa = N / m2 and J = N · m.

PS:

p*V = n*R*T;

代碼如下:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const double R = 8.314;double PP, VV, NN, TT;void findd(char a, double b){    if(a == 'p')    {        PP = b;    }    else if(a == 'V')    {        VV = b;    }    else if(a == 'n')    {        NN = b;    }    else if(a == 'T')    {        TT = b;    }}int main(){    char a;    double b;    while(~scanf("%c = %lf",&a, &b))    {        getchar();        PP = VV = NN = TT = -1;        findd(a,b);        scanf("%c = %lf",&a, &b);        getchar();        findd(a,b);        scanf("%c = %lf",&a, &b);        getchar();        findd(a,b);        if(NN < 0)        {            printf("n = %lf\n",(PP*VV)/(R*TT));        }        else if(PP < 0)        {            printf("p = %lf\n",(NN*R*TT)/(VV));        }        else if(TT < 0 || VV < 0)        {            if(NN==0 && PP==0)            {                printf("undefined\n");            }            else if(NN==0 || PP==0)            {                printf("error\n");            }            else if(TT < 0)            {                printf("T = %lf\n",(PP*VV)/(NN*R));            }            else if(VV < 0)            {                printf("V = %lf\n",(NN*R*TT)/(PP));            }        }    }    return 0;}


URAL 1823. Ideal Gas(數學啊 )

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.