链接:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1282
原题:
Solve the equation:
p*e-x+q*sin(x) +r*cos(x) +s*tan(x) +t*x2+u= 0
where0 <=x<= 1.
Input
Input consists of multiple test cases and terminated by an EOF. Each test case consists of 6 integers in a single line:p,q,r,s,tandu(where0 <=p,r<= 20and-20 <=q,s,t<=
0). There will be maximum 2100 lines in the input file.
Output
For each set of input, there should be a line containing the value ofx, correct upto 4 decimal places, or the string "No solution", whichever is applicable.
Sample Input
0 0 0 0 -2 1
1 0 0 0 -1 2
1 -1 1 -1 -1 1
Sample Output
0.7071
No solution
0.7554
分析与总结:
非线性方程求根问题, LRJ《算法入门经典》p150有类似的问题。 要求的跟是0~1之间, 而且这个方程是单调递减的,所以可以用二分来求根。
/*
* UVa: 10341 - Solve It
* Time: 0.024s
* Result: Accept
* Author: D_Double
*
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#define EPS (10e-8)
using namespace std;
double p,q,r,s,t,u;
inline double fomula(double x){
return p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
}
int main(){
while(scanf("%lf%lf%lf%lf%lf%lf",&p,&q,&r,&s,&t,&u)!=EOF){
double left=0, right=1, mid;
bool flag=false;
if(fomula(left)*fomula(right) > 0){
printf("No solution\n");
continue;
}
while(right-left > EPS){
mid = (left+right)/2;
if(fomula(mid)*fomula(left) > 0) left=mid;
else right=mid;
}
printf("%.4f\n", mid);
}
return 0;
}
分享到:
相关推荐
Algorithm-How-to-Solve-it-by-Computer-R-G-Dromey.zip,如何用计算机求解-r.g.dromey解,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
XPath-Solve.rar XPath-Solve.rar XPath-Solve.rar
藏经阁-Redesigning-PKI-To-Solve-Revocation-Expiration-And-Rotation-Problems.pdf
C-code-to-solve-quadratic-equation-源码.rar
use-design-to-solve-technical-bottlenecks-090419084944-phpapp01
Algorithm-solve-leetcode-problems.zip,这个gitbook包含了我解决的所有leetcode问题。,算法是为计算机程序高效、彻底地完成任务而创建的一组详细的准则。
grDecOrd - solve the problem about decomposition of the digraph to the sections with mutually accessed vertexes (strongly connected components); grDistances - find the distances between any vertexes ...
leetcode中国 怎样解题 leetcode 记得高中时偶然翻到一本小册子,书名叫《怎样解题》。它是美国的一个数学家,教育家写的。 当时我还陷入在应试教育的题海战术中,靠着大量的刷数学题来达到条件式的反射。...
Polya, "How to Solve It" will show anyone in any field how to think straight. In lucid and appealing prose, Polya reveals how the mathematical method of demonstrating a proof or finding an unknown ...
此程序主要是用MATLAB仿真模拟FDTD的主程序,也是最基本的程序。
Create React App入门该项目是通过引导的。可用脚本在项目目录中,可以运行:yarn start在开发模式下运行应用程序。打开在浏览器中查看它。如果您进行编辑,则页面将重新加载。您还将在控制台中看到任何棉绒错误。...
运行ipython 笔记本(在目录内部lets-start-solve-problem-on-kaggle ): ipython notebook 。 注意:您需要在安装ipython之前(以及一些其他所需的软件包),或者仅安装 。 之后,您将完成所有三个步骤(在不同...
Gauss seidel matlab program for feeders
该程序用贪心算法来求解0-1背包问题 采用贪婪准则
利用matlab开发一套求解雷诺方程的办法,利用有限差分法。
逐步解决数独 Vue.js + PixiJS + Flask + Python3 ...cd sudo-dynamic-solve python3 -m venv venv source venv/bin/activate pip install -r requirements.txt flask run 打开浏览器,输入: 享受!
作者: G. Polya 副标题: A New Aspect of Mathematical Method (Princeton Science Library) ISBN: 9780691119663 页数: 288 定价: USD 16.95 出版社: Princeton University Press 装帧: Paperback ...
java-script-probleam-solve
神奇的魅力解决您的心理困境 :high_voltage:...$ cd Magical-Charisma-To-Solve-Your-Mental-Dilemma 部署到GitHub :package: 完成设置后,您应该在线托管网站。 强烈建议您通读的 。 部署到Netlify :package: 您也可