URAL - 1823 Ideal Gas(审题)

Ideal Gas

Time Limit: 500MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

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

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; }
	}
}
时间: 2024-08-01 19:36:56

URAL - 1823 Ideal Gas(审题)的相关文章

URAL 1823. Ideal Gas(数学啊 )

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1823 1823. Ideal Gas Time 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 t

URAL 1823. Ideal Gas 数学,分类

1823. Ideal Gas Time 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, substit

URAL 1823 Ideal Gas

题意: 知道三个变量求剩下一个变量.其中R是已知常量=8.314.其中V,T必须要大于0.如果出现矛盾就输出error.如果出现不确定的情况输出undefined. 这一题构思巧妙 1 #include <iostream> 2 #include <string.h> 3 #include <iomanip> 4 #include <algorithm> 5 using namespace std; 6 double R = 8.314; 7 int a[5

URAL - 1793 Tray 2(几何题)

Tray 2 Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description One of the organizers of the Ural Regional School Programming Contest came to the university cafeteria to have lunch. He took a soup and a ma

ural 1297 Palindrome(Manacher模板题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 求最长回文子串. http://acm.timus.ru/problem.aspx?space=1&num=1297 Manacher模板题,复杂度O(n),做这题纯属是为了验一下自己写的模板是否正确. 当然这题也可以用后缀数组来搞 1 #include <iostream> 2 #include <sstream> 3 #include <ios&g

A1135 | 红黑树判断:审题、根据“先序遍历”和“BST树”的条件生成后序遍历、递归判断

对A1135这题有心里阴影了,今天终于拿下AC.学习自柳神博客:https://www.liuchuo.net/archives/4099 首先读题很关键: There is a kind of balanced binary search tree named red-black tree in the data structure------ 红黑树首先应该是一棵BST树,不然从何谈起维护二分查找结构? 所以第一步就应该根据先序遍历以及BST树的特性来判断是否是一棵BST树,然后根据这两个条

审题习惯 &amp;&amp; debug习惯

做题习惯 静态查错一遍后再测样例 读double型的变量尽量用scanf (int)r * 1000 应写成(int) (r * 1000) 开新题之前,检查这一题的输出格式/数据范围会不会爆long long 对于极端"小数据" 矩阵乘法的时候注意考虑初始化的那几个值,特判输出. 对于取模 做了减法之后取模一定要while(ans<0)ans+=mod; 你读入一个数,若它已经超过模数,直接模!别回头!,ksm的a和k都是可以直接模的 题目要求模一个数的时候看清楚模的是不是质数

URAL 1889. Airport Announcements 模拟题

1889. Airport Announcements Time limit: 1.0 second Memory limit: 64 MB Igor was bored of waiting in an airport lounge. Oceanic Airlines, a company he didn't like so much, delayed the departure of his flight, so he was late for the connection flight t

HDU 5063 Operation the Sequence(仔细审题)

http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i query current value of a[i], this operator will have at most 50. 解题思路: 因为给定n和m都是100000,我们每一步都做具体的操作,时间将是O(n*m),肯定超时.最开始的时候 我怎么想都不知道怎么解决.以为是线段树.比赛完了以后,看了解