URAL - 1823 Ideal Gas(审题)
2015-04-22 01:01
288 查看
Ideal Gas
Submit Status
Description
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.
Input
Each 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).
Output
If 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
比赛时没做出来,注意审题,难点在什么时候输出error,undefined,p=0且n=0时要输出undefined,p=0求n或n=0求p时,因为T和V为正,输入错误,要输出error。
Time Limit: 500MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
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.
Input
Each 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).
Output
If 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
input | output |
---|---|
p = 1 n = 1 V = 1 | T = 0.120279 |
Notes
Recall that Pa = N / m 2 and J = N · m.比赛时没做出来,注意审题,难点在什么时候输出error,undefined,p=0且n=0时要输出undefined,p=0求n或n=0求p时,因为T和V为正,输入错误,要输出error。
#include<iostream> #include<iomanip> using namespace std; const double r = 8.314; int main() { double p, v, n, t; char type, op; double num; while (cin >> type) { p = v = n = t = -1; cin >> op; cin >> num; switch (type) { case 'p': p = num; break; case 'n': n = num; break; case 'V': v = num; break; case 'T': t = num; break; } cin >> type >> op >> num; switch (type) { case 'p': p = num; break; case 'n': n = num; break; case 'V': v = num; break; case 'T': t = num; break; } cin >> type >> op >> num; switch (type) { case 'p': p = num; break; case 'n': n = num; break; case 'V': v = num; break; case 'T': t = num; break; } if (p == 0 && n == 0) { cout << "undefined" << endl; continue; } if (p == 0 && n != -1 || n == 0 && p != -1){ cout << "error" << endl; continue; } if (p == -1) { p = (n*r*t) / v; cout << 'p' << ' ' << '=' << ' ' << fixed << setprecision(6) << p << endl; continue; } if (n == -1) { n = (p*v) / (r*t); cout << 'n' << ' ' << '=' << ' ' << fixed << setprecision(6) << n << endl; continue; } if (v == -1) { v = (n*r*t) / p; cout << 'V' << ' ' << '=' << ' ' << fixed << setprecision(6) << v << endl; continue; } if (t == -1) { t = (p*v) / (n*r); cout << 'T' << ' ' << '=' << ' ' << fixed << setprecision(6) << t << endl; continue; } } }
相关文章推荐
- URAL 1823. Ideal Gas(数学啊 )
- URAL 1823 — Ideal Gas
- URAL 1823. Ideal Gas(数学啊 )
- URAL1992-CVS
- URAL 1992 CVS
- K - Log Files URAL - 2073 ----大模拟
- URAL 2019 Pair: normal and paranormal
- [HDOJ1823] Luck and Love(线段树,树套树)
- 【DP】URAL 2018 The Debut Album
- URAL 题目1553. Caves and Tunnels(Link Cut Tree 改动点权,求两点之间最大)
- ural 1989(树状数组+多项式hash)
- URAL 1614. National Project “Trams” (图论大YY)
- ural 1022. Genealogical Tree 拓扑排序
- ural 1224. Spiral dfs
- URAL-1979 Resources Distribution
- URAL1519 Formula 1(插头dp的基础题 ——详细解释)
- URAL - 1004 Sightseeing Trip(最小环)
- URAL - 2029 Towers of Hanoi Strike Back
- URAL - 1519 :Formula 1
- Ural-1076 Trash(最小费用最大流算法)