uva-10341-二分法
题意:已知方程的根在0-1范围内,求解方程的根,如果方程不存在根,那就输出 no solution.
直接二分,保留四位小数.
#include "pch.h"
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip> namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string;
using std::sort;
using std::priority_queue;
using std::greater;
using std::vector;
using std::swap;
using std::stack; constexpr double MD = 1e-; double p, q, r, s, t, u; double cal(double x)
{
return
p * exp(-x) + q * sin(x) + r * cos(x) + s * tan(x)
+ t * x*x + u; } void solve()
{
while (cin >> p >> q >> r >> s >> t >> u)
{
double l = , r = ;
if (cal(l)*cal(r) > )
{
cout << "No solution" << endl;
continue;
}
while (r - l > MD)
{
double m = (l + r) / ;
if (cal(m)*cal(l) > )
l = m;
else
r = m;
} cout << std::setiosflags(std::ios::fixed) << std::setprecision() << l << endl;; } } }; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return ;
}
uva-10341-二分法的更多相关文章
- UVA 10341 Solve It 解方程 二分查找+精度
题意:给出一个式子以及里面的常量,求出范围为[0,1]的解,精度要求为小数点后4为. 二分暴力查找即可. e^(-n)可以用math.h里面的exp(-n)表示. 代码:(uva该题我老是出现Subm ...
- UVa 10341 (二分求根) Solve It
很水的一道题,因为你发现这个函数是单调递减的,所以二分法求出函数的根即可. #include <cstdio> #include <cmath> //using namespa ...
- uVa 714 (二分法)
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Before th ...
- UVa 10341 - Solve It
题目:给一个方程,求解方程的解.已给出解的范围,并且可知方程等号左侧的函数是递减的,可用二分法进行试探,直到得出给定误差范围内的解. #include <cstdio> #include ...
- 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 the equation:p ∗ e−x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x2 + u = 0where 0 ≤ x ≤ 1.In ...
- 【数值方法,水题】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 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-二分查找
二分查找 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表.首先,假设表中元素是按升序 ...
随机推荐
- NDK学习笔记(二)
花了点时间把pixeliop的部分看完了,拿到开发文档提供的案例稍事修改,把画面左半边压暗. 这个案例重点在于理清pixel_engine()函数中的坐标与scanline的关系. y代表当前正在调用 ...
- linux 服务器之间配置免密登录
客户机:172.16.1.2 远程机:172.16.1.3 1.远程机 a.允许root用户通过22端口登录 vi /etc/ssh/sshd_config PORT 22 PermitRootLog ...
- Ubuntu 14.04 下安装 MongoDB 服务器 和 PHP MongoDB Driver 数据驱动
https://laravel-china.org/topics/309/install-mongodb-server-and-php-mongodb-driver-data-driver-under ...
- c#读取Sybase中文乱码的解决办法
最近需要从Sybase数据库中获取数据.用Sybase.Data.AseClient连接的话比较简单,但中文数据会有乱码.用Sybase自带的工具SQL Advantage设置好编码和语言,是可以正常 ...
- Atom窗口切换和放大或者缩小
Atom窗口切换和放大或者缩小 快捷键就是 F11
- C# name scheme
1.For varibale.camel scheme.the first word lowercase the first letter,then other words capitalize th ...
- Netty Tutorial Part 1: Introduction to Netty [z]
Netty Tutorial, Part 1: Introduction to Netty Update: Part 1.5 Has Been Published: Netty Tutorial P ...
- sass之为什么要使用预处理器
使用预处理器主要目的就是编写出可读性更好.更易于维护的css. 以sass为例,sass中提供了@import可以在sass文件中导入其他sass文件,或在选择器中按需导入所需要的某个属性样式: @i ...
- 滚动效果marquee的用户体验不好,很少被用到,一般用jquery替代
滚动效果marquee的用户体验不好,很少被用到,一般用jquery替代
- JSP基础解析
EL表达式 https://www.cnblogs.com/zhouguanglin/p/8117406.html EL(Expression Language) 是为了使JSP写起来更加简单 ...