UVA10341-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 ;
}
UVA10341-Solve It-二分查找的更多相关文章
- uva10341 - solve it (二分查找)
题目:uva10341-solve it 题目大意:求解给定的方程式解题思路:由于这个方程式在给定的x的范围内是单调递减的.所以能够用二分查找来尝试x的值.这里的 x是要求保留4小数,所以当区间缩小到 ...
- UVA 10341.Solve It-二分查找
二分查找 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表.首先,假设表中元素是按升序 ...
- CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。
1514: Packs Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 61 Solved: 4[Submit][Status][Web Board] ...
- 【二分查找最优解】FZU 2056 最大正方形
题意:现在有一个n*m的矩阵A,在A中找一个H*H的正方形,使得其面积最大且该正方形元素的和不大于 limit. 分析:开始以为是DP或者二维RMQ,其实用二分就可以做出来: 在输入时构造元素和矩阵d ...
- POJ_3685_Matrix_(二分,查找第k大的值)
描述 http://poj.org/problem?id=3685 一个n*n的矩阵,(i,j)的值为i*i+100000*i+j*j-100000*j+i*j,求第m小的值. Matrix Time ...
- 【leetcode边做边学】二分查找应用
很多其它请关注我的HEXO博客:http://jasonding1354.github.io/ 简书主页:http://www.jianshu.com/users/2bd9b48f6ea8/lates ...
- 抄书(B - 二分查找)
抄书 (二分查找+贪心) 提示:二分查找一般写成非递归形式 时间复杂度:O(logn) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action? ...
- 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.问有多少种取法. 思路: ...
- uva11991(二分查找或map的应用)
11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Easy Problem from Rujia Liu? Though R ...
- Long Jumps(二分查找lower_bound()函数的运用)
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long ju ...
随机推荐
- 解决IOS iframe不滚动问题
.frameBox{ position: fixed; top: 0; left: 0; right: 0; bottom: 0; -webkit-overflow-scrolling: touch; ...
- Docker Stack 集群部属服务
Docker越来越成熟,功能也越来越强大.使用Dokcer Stack做服务集群也是非常的方便,docker 自己就提供了负载功能,感觉很方便,就想给大家分享一下,做一个简单的教程. 环境 我是用了两 ...
- CPU31X-2DP通过DP网络连接远程IO站
一.远程IO站介绍 二.该DP网络系统结构 三.组态DP主站 1.组态机架硬件配置 2.设置profibus属性,主站地址为2,如下图 3.完成主站组态 四.组态远程IO从站ET200M 1.接口模块 ...
- MAMP升级mysql5.6到5.7
RT 1.先把mamp环境停掉 sudo sh /Applications/MAMP/bin/stop.sh 2.然后使用brew安装mysql5.7 brew install mysql 3.默认安 ...
- centos 7 部署 汉化版 gitlab
=============================================== 2017/11/12_第6次修改 ccb_warlock 更 ...
- redis 安装方式
1 参考网址 https://www.cnblogs.com/ahjx1628/p/6496529.html https://www.cnblogs.com/smail-bao/p/6164132.h ...
- Xamarin.Android 引导页
http://blog.csdn.net/qq1326702940/article/details/78665588 https://www.cnblogs.com/catcher1994/p/555 ...
- 80 行代码爬取豆瓣 Top250 电影信息并导出到 CSV 及数据库
一.下载页面并处理 二.提取数据 观察该网站 html 结构 可知该页面下所有电影包含在 ol 标签下.每个 li 标签包含单个电影的内容. 使用 XPath 语句获取该 ol 标签 在 ol 标签中 ...
- vue2.0 通过v-html指令渲染的富文本无法修改样式的解决方案
在最近的vue项目中遇到的问题:v-html渲染的富文本,无法在样式表中修改样式: 比如下面的代码,div.descBox里面的p标签的color样式并不是"color: blue" ...
- Linux上leveldb的安装和使用
1.首先从官网上下载leveldb进行编译 git clone https://github.com/google/leveldb.git cd leveldb make 2.将头文件和动态链接库拷到 ...