UVA 10341 二分搜索
Solve the equation:
p ∗ e
−x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x
2 + 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
题意:求解这个等式
题解:我们分析下这个等式,就发现是个单调递减的,二分[0,1]就好了
//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; double q,p,r,s,t,u,a,b;
double check(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)) {
double a = 0.0,b = 1.0;
if(check(a) * check(b) > ) {
printf("No solution\n");continue;
}
else if(fabs(check(0.0)) <= eps){
printf("0.0000\n");continue;
}
else if(fabs(check(1.0)) <= eps) {
printf("1.0000\n");continue;
}
if(check()>) {
a = 1.0;
b = 0.0;
}
else {
b = 1.0;
a = 0.0;
}
while() {
double x = (a+b)/;
double temp = check(x);
if(fabs(temp) <= eps) {
printf("%.4f\n",x);
break;
}
else if(temp > ) {
b = x;
}
else a = x;
}
}
return ;
}
代码
UVA 10341 二分搜索的更多相关文章
- UVA 10341 Solve It 解方程 二分查找+精度
题意:给出一个式子以及里面的常量,求出范围为[0,1]的解,精度要求为小数点后4为. 二分暴力查找即可. e^(-n)可以用math.h里面的exp(-n)表示. 代码:(uva该题我老是出现Subm ...
- 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 二分
题目大意:给6个系数,问是否存在X使得等式成立 思路:二分.... #include <stdio.h> #include <math.h> #define EEE 2.718 ...
- UVa 10341 (二分求根) Solve It
很水的一道题,因为你发现这个函数是单调递减的,所以二分法求出函数的根即可. #include <cstdio> #include <cmath> //using namespa ...
- 【数值方法,水题】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 - 10341
Solve the equation:p ∗ e ^−x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x ^2 + u = 02 + u = 0where ...
- UVA 10341.Solve It-二分查找
二分查找 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表.首先,假设表中元素是按升序 ...
- [LeetCode] Largest BST Subtree 最大的二分搜索子树
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...
随机推荐
- Get 和 Post方法的登录
1. Get & Post 1> Get请求直接从服务器拿数据 性能好 效率高 在地址栏会显示所有的参数,从直观上安全性不高 由于Get不提交数据给服务器,因此实际的安全性高 实际应用: ...
- Run ionic web app in nodejs
首先需要express插件:sudo npm install express 将ionic project的www拷贝至wwwroot,新建server.js: var express = requi ...
- SQL开发技巧(二) 【转】感觉他写的很好
本文转自: http://www.cnblogs.com/marvin/p/DevelopSQLSkill_2.html 本系列文章旨在收集在开发过程中遇到的一些常用的SQL语句,然后整理归档,本系列 ...
- sql server 查询数据库所有的表名+字段
SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='Account' SELECT (case when a.colorder= ...
- [原创]flexslider 中文文档 使用教程 参数手册
要改前人用的flexslider功能,但苦于找不到详细的文档教程,折磨了好久……(所以我才说不爱乱用插件) 为了福利下之后也苦于这个问题的人,我整理总结了下我找到的一些东西.可能没那么完善正确,欢迎在 ...
- opencv颜色识别代码分享
android 平台 opencv 实现颜色识别代码:http://www.eyesourcecode.com/thread-40682-1-1.htmlopencv的颜色识别简单实现的代码:http ...
- C++编程显示四则运算题目
题目:C++编程显示四则运算题目 设计思路:(1)让用户自己确定出题的数量,同时显示加减乘除四则运算. (2)考虑到用户可能只会一种运算,因此可以选择运算.
- (转载)HTML:模拟链接被按下,在新标签页打开页面,不使用window.open(可能被拦截)
原文: http://www.cppblog.com/biao/archive/2010/08/21/124196.html 当按下一个按钮时,想打开一个新的标签页,可以使用window.open去实 ...
- struts2 action获取ajax提交数据中文乱码问题
有个人和我问题相同,地址在这: 解决方法: 在ajax的属性添加这句:contentType:'application/x-www-form-urlencoded; charset=utf-8',
- Kibana4学习<二>
生产环境部署 Kibana4 是是一个完整的 web 应用.使用时,你需要做的只是打开浏览器,然后输入你运行 Kibana 的机器地址然后加上端口号.比如说:localhost:5601 或者 htt ...