UVA10341 Solve It
题意
分析
在\(0\le x\le 1\)时,\(f(x)=pe^{-x}+q\sin x+r\cos x+s\tan x+tx^2+u\)是减函数,所以当\(f(0)\ge 0 \wedge f(1)\le 0\)时,函数有唯一零点,否则没有。
那么二分答案即可。控制二分次数,时间复杂度\(O(100)\)
代码
#include<bits/stdc++.h>
#define rg register
#define il inline
#define co const
template<class T>il T read(){
rg T data=0,w=1;rg char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') w=-1;ch=getchar();}
while(isdigit(ch)) data=data*10+ch-'0',ch=getchar();
return data*w;
}
template<class T>il T read(rg T&x) {return x=read<T>();}
typedef long long ll;
#define F(x) (p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*(x)*(x)+u)
co double eps=1e-14;
int main(){
// freopen(".in","r",stdin),freopen(".out","w",stdout);
int p,r,q,s,t,u;
while(~scanf("%d%d%d%d%d%d",&p,&q,&r,&s,&t,&u)){
if(F(1)>eps||F(0)<-eps) {puts("No solution");continue;}
double x=0,y=1,m;
for(int i=0;i<100;++i){
m=(x+y)/2;
F(m)<0?y=m:x=m;
}
printf("%.4lf\n",m);
}
return 0;
}
UVA10341 Solve It的更多相关文章
- uva10341 - solve it (二分查找)
题目:uva10341-solve it 题目大意:求解给定的方程式解题思路:由于这个方程式在给定的x的范围内是单调递减的.所以能够用二分查找来尝试x的值.这里的 x是要求保留4小数,所以当区间缩小到 ...
- UVA 10341.Solve It-二分查找
二分查找 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表.首先,假设表中元素是按升序 ...
- .Uva&LA部分题目代码
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...
- UVA10341-Solve It-二分查找
二分查找 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表.首先,假设表中元素是按升序 ...
- UVA10341:Solve It(二分+math.h库)
题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68990#problem/E 题目要求:p*e-x+ q*sin(x) + r*co ...
- Solve VS2010 Error "Exceptions has been thrown by the target of an invocation"
Sometimes when you open a VS2010 project, an error window will pop up with the error message "E ...
- solve the problem of 'java web project cannot display verification code'
my java code of the function: package com.util; import java.awt.Color; import java.awt.Font; import ...
- HDU1086You can Solve a Geometry Problem too(判断线段相交)
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
- Solve
/// <summary> /// Solves this instance. /// </summary> /// <returns>IFeatureClass. ...
随机推荐
- day12-python的类
类的一般形式: 创建类我们一般用class关键字来创建一个类,class后面跟类名字,可以自定义,最后以冒号结尾,如下所示: class ClassName: '''类的说明''' 类的内容 类的内容 ...
- [Codeforces708E]Student's Camp
Problem 一个n*m块砖的建筑,一共k天,每天风从两边吹,吹掉砖的概率为p,反之为1-p,求最终建筑没有倒塌的可能性(上层与下层有交集且每一层都有砖) Solution 首先,我们可以预处理出p ...
- Jenkins持续集成web项目(七)
功能:用户开发完maven构建的web项目后,从本地提交代码到gogs远程仓库中,在执行 git commit 命令之前会先执行 maven配置的 findbugs插件,来检测项目是否有明显bug,如 ...
- CSS--思维导图
CSS--思维导图
- 以黄门镇黄湾村某一扶贫文档为例——将Excel数据填入到已存在的Word模板
傻瓜可以写出机器读得懂代码,但写出让人能读懂的代码的是优秀程序员 作用:通过Excel文件中的一列数据作为文件名创建Word文档,并将Excel中的一行数据填一表,实现自动化 Excel的VBA宏代码 ...
- Android : android 8.0 audio 接口分析
1.HIDL 的概念 HIDL 读作 hide-l,全称是 Hardware Interface Definition Language.它在 Android Project Treble 中被起草, ...
- 对弈的Python学习笔记
#主要序列类型 str list tuple #列表 list ls=[1,2,3,4]#末尾追加ls.append(5) #添加多个,扩展ls.extend([5,6,7]) #在某个位置插入一个值 ...
- 2019.1.23 DFMEA for
- Word2Vec实现原理(Hierarchical Softmax)
由于word2vec有两种改进方法,一种是基于Hierarchical Softmax的,另一种是基于Negative Sampling的.本文关注于基于Hierarchical Softmax的改进 ...
- Could not load driverClass com.mysql.jdbc.Driver错误
在整合spring和mybatis的时候,在spring配置文件中已经加载了db.properties并配置了c3p0数据源 但在写了一个测试类测试是否取到了数据库的连接时,报错:Could not ...