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. 1.6e-04 1.0e-01 1 1
  2. 1.6e-04 1.0e-01 4 1
  3. 1.5e-05 5.0e-02 1 2
  4. 0 0 0 0

Sample Output

  1. 2.407
  2. 2.101
  3. 3.216

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

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

代码:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <vector>
  5. #include <string>
  6. #include <cstring>
  7. #pragma warning(disable:4996)
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. double ka;
  13. double ori_con;
  14. int m;
  15. int n;
  16.  
  17. while(1)
  18. {
  19. cin>>ka;
  20. cin>>ori_con;
  21. cin>>m;
  22. cin>>n;
  23.  
  24. if(ka+ori_con+m+n==0)
  25. break;
  26. double x=(sqrt(ka*ka+4*ka*ori_con*m*n)-ka)/(2*n);
  27.  
  28. printf("%.3f\n",-log10(x));
  29. }
  30. return 0;
  31. }

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

POJ 2006:Litmus Test 化学公式的更多相关文章

  1. 解方程求PH值,POJ(2006)

    题目链接:http://poj.org/problem?id=2006 解题报告: 题意看了半天,没看懂,再加上化学没学好,更加让我头痛. 假设1L溶解了x摩尔的酸:ka=m*x*nx/ori-x; ...

  2. poj 1833 排列 STL 全排列公式

    排列 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15173   Accepted: 6148 Description 题 ...

  3. anki2.1中使用latex,使用 MathJax 渲染latex格式的数学公式,化学公式

    说说mathJax的优点: 不在anki媒体库生成图片,有利于节约手机空间. 再说说它的缺点:需要学习latex,需要一些时间去掌握latex语法. 1.去MathJax的github下载源码包 2. ...

  4. 如何将公式插入到word

    平台:win10 x64+ office 2010+ Mathpix Snipping Tool +mathtype6.9b   直接安装就行,下载好了以后,要和word连接起来还需要下载一个插件,有 ...

  5. 来吧,HTML5之基础标签(下)

    <dialog> 标签 定义对话框或窗口. <dialog> 标签是 HTML 5 的新标签.目前只有 Chrome 和 Safari 6 支持 <dialog>  ...

  6. web项目开发规范整理总结

    一.类.函数.变量名命名: 1.定义类时,全部拼音的首字母必须大写:如Person,ClassDemo:(帕斯卡命名法):也可以用带下斜杆的匈牙利命名法进行命名,如    head_navigatio ...

  7. html, xhtml和xml

    html, xhtml和xml 1.定义及特点: 1) html:Hyper Text Markup Language 超文本标记语言 是最早写网页的语言,但编码不规范,主要用于控制数据的显示和外观. ...

  8. HTML标签拾遗

    在日常的开发过程中,经常与HTML标签打交道,常用的标签往往是那么几个,在此记录下后续可能会用到的html标签,或许会有意向不到的奇效.全部内容来自w3cschool. <abbr>   ...

  9. HTML内联元素

    前面的话 用于标记段落里的文本和其他内容组的元素种类很多,本文将这些文本级元素进行简单分类,便于整理和记忆 通用容器 <span>元素是短语内容的通用行内容器,并没有任何特殊语义.可以使用 ...

随机推荐

  1. 048、Java中使用switch判断

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  2. java 根据值获取枚举对象

    关键方法: /** * 值映射为枚举 * * @param enumClass 枚举类 * @param value 枚举值 * @param method 取值方法 * @param <E&g ...

  3. @Resource 和@Autowired区别

    @Autowired 该注解是由spring提供的 按照类型注入 public class UserService { @Autowired private UserDao userDao; } 这样 ...

  4. CANmonitor我自己编写的程序

    这个版本的程序, 上位机可以对电机的转速进行在线的设定,同时上位机接受电机控制器上报的母线电压,电机温度,控制器温度等. 在调试的过程中我遇见了一个问题,电机的转速的采样 . 根据协议:电机的转速为1 ...

  5. idea下maven项目下spring junit 测试用例

    使用idea在编写的类下右键Go->Test或者ctrl+shift+t,点击create new test会在相应目录下创建test类 别写代码如下 @RunWith(value = Spri ...

  6. 080-PHP的if与elseif用法

    <?php /* 正确的使用方法: */ $a = 10; $b = 20; if ($a > $b): echo $a . "大于" . $b; elseif ($a ...

  7. JAVA-数据类型-复习

    JAVA-数据类型-复习 Java中,一共有8种数据类型,4种整型,2种浮点型,1种用于表示Unicode编码的字符单元的字符类型char,1种布尔类型. 整型 类型 存储需求(字节)一个字节包含8个 ...

  8. 利用ThoughtWorks.QRCode生成二维码

    一.项目添加ThoughtWorks.QRCode.dll和System.Drawing.dll的引用 二.创建二维码公共处理类(QRCodeHandler.cs) /// <summary&g ...

  9. 逆向-PE导入表

    导入表 动态链接库需要导入表 结构 typedef struct _IMAGE_IMPORT_DESCRIPTOR { union { DWORD Characteristics; // 0 for ...

  10. kafka源码系列之mysql数据增量同步到kafka

    一,架构介绍 生产中由于历史原因web后端,mysql集群,kafka集群(或者其它消息队列)会存在一下三种结构. 1,数据先入mysql集群,再入kafka 数据入mysql集群是不可更改的,如何再 ...