UVA 10341.Solve It-二分查找
二分查找
Solve the equation:
p∗e−x + q∗sin(x) + r∗cos(x) + s∗tan(x) + t∗x2 + u = 0
where 0 ≤ 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, t and u (where 0 ≤ p, r ≤ 20 and −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 of x, correct up to 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
代码如下:
#include<stdio.h>
#include<math.h>
const double eps=1e-7;
int p,q,r,s,t,u;
double fun(double x){
return p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
}
int main(){
while(~scanf("%d%d%d%d%d%d",&p,&q,&r,&s,&t,&u)){
double maxx=1.0,minn=0.0,mid;
if(fun(maxx)*fun(minn)>){
printf("No solution\n");
continue;
}
while(minn+eps<maxx){
mid=(maxx+minn)/2.0;
if(fun(mid)<=) maxx=mid;
else minn=mid;
}
printf("%.4f\n",mid);
}
return ;
}
UVA 10341.Solve It-二分查找的更多相关文章
- UVA 10341 Solve It 二分
题目大意:给6个系数,问是否存在X使得等式成立 思路:二分.... #include <stdio.h> #include <math.h> #define EEE 2.718 ...
- UVA 10341 Solve It 解方程 二分查找+精度
题意:给出一个式子以及里面的常量,求出范围为[0,1]的解,精度要求为小数点后4为. 二分暴力查找即可. e^(-n)可以用math.h里面的exp(-n)表示. 代码:(uva该题我老是出现Subm ...
- uva10341 - solve it (二分查找)
题目:uva10341-solve it 题目大意:求解给定的方程式解题思路:由于这个方程式在给定的x的范围内是单调递减的.所以能够用二分查找来尝试x的值.这里的 x是要求保留4小数,所以当区间缩小到 ...
- UVa 10341 - Solve It【经典二分,单调性求解】
原题: Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where ...
- 【数值方法,水题】UVa 10341 - Solve It
题目链接 题意: 解方程:p ∗ e^(−x) + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x^2 + u = 0 (0 <= x <= 1) ...
- UVa 10341 - Solve It
题目:给一个方程,求解方程的解.已给出解的范围,并且可知方程等号左侧的函数是递减的,可用二分法进行试探,直到得出给定误差范围内的解. #include <cstdio> #include ...
- UVa 1152 和为0的4个值(二分查找)
https://vjudge.net/problem/UVA-1152 题意:给定4个n元素集合A,B,C,D,要求分别从中选取一个元素a,b,c,d,使得a+b+c+d=0.问有多少种取法. 思路: ...
- UVA.10474 Where is the Marble ( 排序 二分查找 )
UVA.10474 Where is the Marble ( 排序 二分查找 ) 题意分析 大水题一道.排序好找到第一个目标数字的位置,返回其下标即可.暴力可过,强行写了一发BS,发现错误百出.应了 ...
- UVa 10539 (筛素数、二分查找) Almost Prime Numbers
题意: 求正整数L和U之间有多少个整数x满足形如x=pk 这种形式,其中p为素数,k>1 分析: 首先筛出1e6内的素数,枚举每个素数求出1e12内所有满足条件的数,然后排序. 对于L和U,二分 ...
随机推荐
- C#中的SubString()的用法
先看语法: String.SubString(int index,int length) index:开始位置,从0开始 length:你要取的子字符串的长度 例子: using ...
- 纯真IP数据库(qqwry.dat)转换成最新的IP数据库格式(ipwry.dat)
纯真IP数据库(qqwry.dat)转换成最新的IP数据库格式(ipwry.dat) 转载自:http://blog.cafeboy.org/2011/02/25/qqwry-to-ipwry/ ht ...
- 【题解】SDOI2011消耗战
虚树模板题~洛谷P2495 第一次写虚树,感觉好厉害呀~首先,这道题目的树形dp是非常显然的,要控制一个点&其子树所有点,要么在子树内部割边,要么直接切点该点与父亲的连边.所以dp[u]表示控 ...
- ext radiogroup如何取值和设值
var radios = Ext.create('Ext.form.Panel', { title: 'RadioGroup Example', width: 300, height: 125, bo ...
- 论文讨论&&思考《Deformable Convolutional Networks》
这篇论文真是让我又爱又恨,可以说是我看过的最认真也是最多次的几篇paper之一了,首先deformable conv的思想我觉得非常好,通过end-to-end的思想来做这件事也是极其的make se ...
- POJ1637:Sightseeing tour(混合图的欧拉回路)
Sightseeing tour Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10581 Accepted: 4466 ...
- Elasticsearch 5.2.1Cluster 搭建
1.安装java cd ~ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fw ...
- PHP正则替换preg_replace函数的使用
<?php $str="as2223adfsf0s4df0sdfsdf"; echo preg_replace("/0/","",$s ...
- notepad++中快速插入当前时间方法
转载自:http://blog.csdn.net/donghustone/article/details/7436483 在notepad++中快速插入当前时间方法: 插件是notepad++的一大优 ...
- domReady的兼容性实现方法
一.为何要实现domReay方法? 举例: <!DOCTYPE html> <html lang="en"> <head> <meta c ...