UVa 10341 - Solve It
题目:给一个方程,求解方程的解。已给出解的范围,并且可知方程等号左侧的函数是递减的,可用二分法进行试探,直到得出给定误差范围内的解。
#include <cstdio>
#include <cmath>
#define EPSILON 1e-9 int p, q, r, s, t, u; double f(double x)
{
return p*exp(-1.0*x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u;
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
while (scanf("%d%d%d%d%d%d", &p, &q, &r, &s, &t, &u) != EOF)
{
if (f() < || f() > )
{
printf("No solution\n");
continue;
}
double x = , y = ;
while (y - x > EPSILON)
{
double m = (x+y)/;
if (f(m) < ) y = m;
else x = m;
}
printf("%.4lf\n", x);
}
return ;
}
开始的时候WA了一次,后来把EPSILON的值从1e-6调成1e-9就好了,又是这个问题...
UVa 10341 - Solve It的更多相关文章
- 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-二分查找
二分查找 二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好:其缺点是要求待查表为有序表,且插入删除困难.因此,折半查找方法适用于不经常变动而查找频繁的有序列表.首先,假设表中元素是按升序 ...
- UVA 10341 Solve It 二分
题目大意:给6个系数,问是否存在X使得等式成立 思路:二分.... #include <stdio.h> #include <math.h> #define EEE 2.718 ...
- 【数值方法,水题】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 <cmath> //using namespa ...
- 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 the equation:p ∗ e ^−x + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x ^2 + u = 02 + u = 0where ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
随机推荐
- java工程开发之图形化界面之(第三课)
上面我们讲述了通过JOptionPane进行文本I/O操作,一个是通过JOptionPane来获取的 参考链接:http://blog.sina.com.cn/s/blog_993d254201013 ...
- jquery判断节点是否存在
if($('.onloadMore').length>0){ return '节点存在'; }else{ return '节点不存在'; }
- Application对象
Application对象报讯是应用程序参数的额,多个用户可以共享一个Application.用于启动和管理ASP.NET应用程序. Count 属性 获取Application对象变量的个数,集合 ...
- iptables原理详解以及功能说明
原文:http://www.svipc.com/thread-450-1-1.html 前言 iptables其实就是Linux下的一个开源的信息过滤程序,包括地址转换和信息重定向等功能的,他由四 ...
- javascript OOP 面向对象编程
Pseudo-class declaration 原文地址:http://javascript.info/tutorial/pseudo-classical-pattern#pseudo-class- ...
- 转: window中使用PSFTP/WinSCP实现SFTP上传下载
sftp 服务器: dbmonitor 1.sftp属于交互式的,所以你得缓存下命令#!/bin/shsftp -o Port=3322 root@172.16.1.21:/opt << ...
- idx_rebuild_diff_idx_l.sql
1. set echo on feedback on set timing on set time on set pagesize 1000 set linesize 150 spool 02_do_ ...
- Java中关于HashMap的使用和遍历(转)
Java中关于HashMap的使用和遍历 分类: 算法与数据结构2011-10-19 10:53 5345人阅读 评论(0) 收藏 举报 hashmapjavastringobjectiterator ...
- 开始学习MFC
<<对0基础MFC者的一点建议>>---------------------摘自某论坛lint2008的回复,不管对错,先看看. 因为上半年自己刚刚学了点MFC,算是对 ...
- 安卓图表引擎AChartEngine(六) - 框架源码结构图
包结构: org.achartengine: org.achartengine.model: org.achartengine.renderer: org.achartengine.tools: 安卓 ...