Litmus Test
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 1709   Accepted: 897

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



The formula for calculating pH is 

pH = -log10 [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 

Ka = [H+] [acid ions] / [acid]


where Ka 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 Ka 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

这个题目的一个收获是我发现指数形式也可以直接使用cin输入,还有log10这个函数。

根据题目给出的第二个公式得到 Ka = mx*nx / ori_con-x,解关于x的方程。最终要转换成-log10 x的形式。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int main()
{
double ka;
double ori_con;
int m;
int n; while(1)
{
cin>>ka;
cin>>ori_con;
cin>>m;
cin>>n; if(ka+ori_con+m+n==0)
break;
double x=(sqrt(ka*ka+4*ka*ori_con*m*n)-ka)/(2*n); printf("%.3f\n",-log10(x));
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. thinkphp 3.2.3 session 丟失問題
  2. shell---变量自增
  3. TypeId和IidManager关系
  4. Windows配置mycat
  5. Azure Backup 入门
  6. zepto下动画返回顶部
  7. POJ 2250 Compromise (UVA 531)
  8. akoj-1073- Let the Balloon Rise
  9. Scrum Meeting 博客
  10. fft的实现
  11. iOS中block循环引用问题
  12. 【xsy3423】党&#178; 线段树+李超线段树or动态半平面交
  13. windows 7 Alt+Tab 的风格改成 XP 风格
  14. QT全局宏变量的实现
  15. 【linux】ls常用参数
  16. Codeforces Round #358 (Div. 2) A B C 水 水 dfs序+dp
  17. Git gitconfig 配置
  18. unity, 3dmax制作的morph(blendshape)导入unity中使用注意事项
  19. Secure Spring REST API using Basic Authentication
  20. redirect_uri域名与后台配置不一致,错误码:10003

热门文章

  1. 求第K大数(分治)
  2. linux systemctl命令
  3. Day5-T2
  4. elasticsearch-java客户端测试
  5. GoJS最简单的实例
  6. centos7安装google-chrome和chromedriver
  7. Arch系linux配置Go开发环境
  8. 强制数据类型转换 字符串/数字/boolean
  9. UVA - 11186 Circum Triangle (几何)
  10. 动手实验01-----vCenter 微软AD认证配置与用户授权