URAL 1823. Ideal Gas 数学,分类

1823. Ideal Gas

Time limit: 0.5 secondMemory 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 gasp, the amount of substancen, the volume occupied by the gasV, and the temperatureT. 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.

Input

Each of the three input lines has the form “X = value”, whereXis the symbol for a physical quantity andvalueis 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 constantRshould be taken equal to 8.314 J / (mol · K).

Output

If the input data are inconsistent, output the only line “error”. If the value ofXcan be determined uniquely, output it in the format “X = value” with an accuracy of 103. If it is impossible to uniquely determine the value ofX, output the only line “undefined”.

Sample

inputoutput

p = 1n = 1V = 1T = 0.120279

Notes

Recall that Pa = N / m2and J = N · m.

高中学的:pV=nRT,即理想气体状态方程

题意:知道三个变量求剩下一个变量。其中R是已知常量=8.314。其中V,T必须要大于0。如果出现矛盾就输出error。如果出现不确定的情况输出undefined。

分类:以求V为例子。如果p和n 有只一个为0 那T和V中也必须有个是等于0的。所以和题意矛盾。输出error。 如果p,,n同时为0,那么就无法求出V是多少。输出undefined。 其他情况直接计算即可。

#include <stdio.h>#include <stdlib.h>#include <string.h> #include <string>#include <iostream>#include <algorithm>using namespace std; #include <vector> int main(){ int data[5];char p[3];string tem;int flag=1;memset(data,-1,sizeof data);for(int i=0;i<3;i++){int num;cin>>p[i];cin>>tem;cin>>num;if(p[i]=='p')data[0]=num;if(p[i]=='V')data[1]=num;if(p[i]=='n')data[2]=num;if(p[i]=='T')data[3]=num;} if(data[1]==0||data[3]==0){puts("error");return 0;}int wei;for(int i=0;i<4;i++)//找出未知数{if(data[i]==-1)wei=i;} double r=8.314;if(wei==0)//计算p data[1]不会等于0 所以不用多做考虑{printf("p = %lf\n",r*(data[2]*data[3])/data[1]);}else if(wei==1)//计算V{if(data[0]==0&&data[2]==0)//如果等式上下都是0 那么就是无法确定,puts("undefined"); else if(data[0]==0||data[2]==0)//如果p等于0 n不等于0 那T必须是0 矛盾。反之,V不能是0 也矛盾puts("error"); elseprintf("V = %lf\n",r*(data[2]*data[3])/data[0]);}else if(wei==2)//计算n{printf("n = %lf\n",1.0*(data[0]*data[1])/data[3]/r);}else if(wei==3)//计算T{ if(data[0]==0&&data[2]==0) //如wei==1puts("undefined");else if(data[0]==0||data[2]==0)puts("error"); elseprintf("T = %lf\n",1.0*(data[0]*data[1])/data[2]/r);}return 0;}/*T = 1n = 0p = 0*/

愈想得到,就愈要放手。放手是很难的,但是别无选择。

URAL 1823. Ideal Gas 数学,分类

相关文章:

你感兴趣的文章:

标签云: