Algorithm title: POJ 2006 Litmus Test (simple math & ionization constants of weak acid)

Source: Internet
Author: User
Tags constant time limit

Litmus Test

http://poj.org/problem?id=2006

Time limit:1000ms

Memory limit:30000k

Description

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 are basic, and 7 if it is neutral.

The formula for calculating PH

PH =-log [H +]

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

To calculate the PH value of a acid, one has to determine the concentration of protons in the solution. When a acid is dissolved in water, a equilibrium is reached and are governed by the equation

K a = [H +] [acid ions]/[acid]

Where Ka is the acidity constant (known for all acid), [acid ions] is the concentration of the acid ions that ha ve 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 *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 is 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 Ka and the original concentration of the acid (in Moles/liter) added to the water, as OK as two positive and integers m and n indicating that each mole of acid molecules are dissolved into m moles of H+ ions and n moles of acid ions. The floating-point numbers are specified in scientific notation as shown. 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

If the acid is ionized by the X mol, then there is a ka= (MX*NX)/(C-x), and an x is multiplied by M that is [h+] ([matter] indicates the concentration of the substance)

Complete code:

/*110ms,192kb*/
  
#include <cstdio>
#include <cmath>
  
int main (void)
{
    double ka, acid ;
    int m, n;
    while (scanf ("%lf%lf%d%d", &ka, &acid, &m, &n), m)
        printf ("%.3f\n",-log10 (-ka + sqrt (ka * ka + (M &l t;< 2) * n * acid 

* ka))/(n << 1));
    return 0;
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.