POJ 2006:Litmus Test 化学公式
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 1709 | Accepted: 897 |
Description
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
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
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 2006:Litmus Test 化学公式的更多相关文章
- 解方程求PH值,POJ(2006)
题目链接:http://poj.org/problem?id=2006 解题报告: 题意看了半天,没看懂,再加上化学没学好,更加让我头痛. 假设1L溶解了x摩尔的酸:ka=m*x*nx/ori-x; ...
- poj 1833 排列 STL 全排列公式
排列 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 15173 Accepted: 6148 Description 题 ...
- anki2.1中使用latex,使用 MathJax 渲染latex格式的数学公式,化学公式
说说mathJax的优点: 不在anki媒体库生成图片,有利于节约手机空间. 再说说它的缺点:需要学习latex,需要一些时间去掌握latex语法. 1.去MathJax的github下载源码包 2. ...
- 如何将公式插入到word
平台:win10 x64+ office 2010+ Mathpix Snipping Tool +mathtype6.9b 直接安装就行,下载好了以后,要和word连接起来还需要下载一个插件,有 ...
- 来吧,HTML5之基础标签(下)
<dialog> 标签 定义对话框或窗口. <dialog> 标签是 HTML 5 的新标签.目前只有 Chrome 和 Safari 6 支持 <dialog> ...
- web项目开发规范整理总结
一.类.函数.变量名命名: 1.定义类时,全部拼音的首字母必须大写:如Person,ClassDemo:(帕斯卡命名法):也可以用带下斜杆的匈牙利命名法进行命名,如 head_navigatio ...
- html, xhtml和xml
html, xhtml和xml 1.定义及特点: 1) html:Hyper Text Markup Language 超文本标记语言 是最早写网页的语言,但编码不规范,主要用于控制数据的显示和外观. ...
- HTML标签拾遗
在日常的开发过程中,经常与HTML标签打交道,常用的标签往往是那么几个,在此记录下后续可能会用到的html标签,或许会有意向不到的奇效.全部内容来自w3cschool. <abbr> ...
- HTML内联元素
前面的话 用于标记段落里的文本和其他内容组的元素种类很多,本文将这些文本级元素进行简单分类,便于整理和记忆 通用容器 <span>元素是短语内容的通用行内容器,并没有任何特殊语义.可以使用 ...
随机推荐
- 浅谈JVM线程调度机制及主要策略
在之前有说过线程,应该都知道,所谓线程就是进程中的一个子任务,一个进程有多个线程.今天的话主要就是谈一谈JVM线程调度机制.我们结合线程来说,当我们在做多线程的案例时,如一个经典案例,火车站卖票. * ...
- docker安装centos7镜像
拉取centos7镜像[root@localhost ~]# docker pull centos:71启动镜像centos7,如果不指定 /bin/bash,容器运行后会自动停止[root@loca ...
- 面试-PA和XSYX面试小结
XSYX 1.自我介绍 2. 最近一个项目的业务和技术栈 3. 分布式锁解决库存问题 4. spring的IOC和AOP讲解 5. 类加载器层级 6.线程池核心参数和问题 7. 期待的团队是怎样的? ...
- 深度学习之常用linux命令总结
深度学习中常用linux命令总结 1.创建文件夹 mkdir 文件名2.删除文件 rm -d 目录名 #删除一个空目录 rmdir 目录名 #删除一个空目录 rm -r 目录名 #删除一个非空目录 r ...
- 关于http的两种上传方法
http传输数据GET和POST的两种方法: 1.Post传输数据时,不需要在URL中显示出来,而Get方法要在URL中显示. 2.get方式传递的参数可以在URL上看见,安全性不高,反之post安全 ...
- python三大神器===》生成器
1. 认识生成器 利用迭代器,我们可以在每次迭代获取数据(通过next()方法)时按照特定的规律进行生成.但是我们在实现一个迭代器时,关于当前迭代到的状态需要我们自己记录,进而才能根据当前状态生成下一 ...
- 我编写的EEPROM 上位机软件
进入模式: 上位机发送 消息 上位机EEPROM 按下进入模式 消息的ID号是:0x08111111 数据是: 00 01 ff 00 00 00 00 00 上位机显示 运行状态 :为进入模式 当我 ...
- python学习笔记2018-9-18
1.可选参数传递 此处m=1并不是写定m必为1,而是m为可选参数,当不对其进行赋值时,其默认值为1. 2.函数的返回值 return可以传递0个返回值,也可以传递任意多个返回值 3.局部变量与全局变量 ...
- Swift 访问权限
internal 内部的 1.默认情况下所有的类&属性&方法的访问权限都是internal 2.在本模块(项目/包/target)中可以访问 private 私有的 1.只有在本类中访 ...
- IISHelper操作iis
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...