ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

POJ-2006 Litmus Test 高精度

2019-09-30 14:00:10  阅读:333  来源: 互联网

标签:pH ions solution POJ Test 2006 concentration acid moles


The pH scale measures the concentration of protons (H +) in a solution and, therefore, its acidity or alkalinity. The pH value of a solution is a number between 0 and 14; it is less than 7 if the solution is acidic, greater than 7 if the solution is basic, and 7 if it is neutral.

The formula for calculating pH is
pH = -log 10 [H +]

where [H +] is the concentration of protons measured in moles per litre.

To calculate the pH value of an acid, one has to determine the concentration of protons in the solution. When an acid is dissolved in water, an equilibrium is reached and is governed by the equation
K a = [H +] [acid ions] / [acid]

where K a is the acidity constant (known for each acid), [acid ions] is the concentration of the acid ions that have dissolved, and [acid] is the concentration of the undissolved acid. Before the acid is added, both [H +] and [acid ions] are assumed to be 0.
For example, the acidity constant of methanoic acid is 1.6 * 10 -4. Dissolving one mole of acid molecules results in one mole of H + and one mole of acid ions. If the initial concentration of the methanoic acid is 0.1 moles/L and x moles of acid are dissolved (per liter), then the final concentration at equilibrium would be 0.1 - x moles/L for the acid and x moles/L for H + and the acid ions. Input The input consists of a number of test cases. Each test case contains 4 numbers on a line: two positive floating-point numbers specifying the acidity constant K a and the original concentration of the acid (in moles/liter) added to the water, as well as two positive integers m and n indicating that each mole of acid molecules is dissolved into m moles of H + ions and n moles of acid ions. The floating-point numbers are specified in scientific notation as shown below. The input is terminated with a line containing four zeros.
Output For each test case, print on a line the pH value of the solution, rounded to 3 decimal places. Sample Input
1.6e-04 1.0e-01 1 1
1.6e-04 1.0e-01 4 1
1.5e-05 5.0e-02 1 2
0 0 0 0
Sample Output
2.407
2.101
3.216


OJ-ID:
POJ-2006

author:
Caution_X

date of submission:
20190929

tags:
卡常的水题

description modelling:
给定电离平衡常数Ka,溶液未电离时的浓度C,1mol 酸的氢含量n和酸根含量m

major steps to solve it:
    常规化学题的推导:设[H+]=x,[酸根]=y,则Ka=x*y/(C-y),x/y=n/m.
    记Ka=a,C=b,解得:ans=(-log10((-a+sqrt(a*a+(4.0*a*b*n*m)))/(2.0*m))).

warnings:
sqrt(n/m)会导致精度不足,用sqrt(n*m)/m来替代则AC

AC CODE:
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdio>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    double a,b;
    int n,m;
    while(~scanf("%lf%lf%d%d",&a,&b,&n,&m)&&a&&b&&n&&m)
    { 
        cout<<setprecision(3)<<fixed<<(-log10((-a+sqrt(a*a+(4.0*a*b*n*m)))/(2.0*m)))<<endl;
    } 
    return 0; 
}
View Code

 





标签:pH,ions,solution,POJ,Test,2006,concentration,acid,moles
来源: https://www.cnblogs.com/cautx/p/11612475.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有