UVA 10341 Solve It 解方程 二分查找+精度
题意:给出一个式子以及里面的常量,求出范围为[0,1]的解,精度要求为小数点后4为。
二分暴力查找即可。
e^(-n)可以用math.h里面的exp(-n)表示。
代码:(uva该题我老是出现Submission Error,过几天再试看看)
/*
* Author: illuz <iilluzen@gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: uva10241.cpp
* Lauguage: C/C++
* Create Date: 2013-08-25 15:37:46
* Descripton: UVA 10341 Solve It, bisection
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL; /****** TEMPLATE ENDS ******/ double p, q, r, s, t, u; #define calc(x) (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)) {
if (calc(0) < 0 || calc(1) > 0) printf("No solution\n");
else {
double x1 = 0, x2 = 1;
while (abs(x1 - x2) >= 1e-10) {
double x = (x1 + x2) / 2.0;
if (calc(x) > 0) x1 = x;
else x2 = x;
}
printf("%.4lf\n", x1);
}
}
return 0;
}
UVA 10341 Solve It 解方程 二分查找+精度的更多相关文章
- 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
题目链接 题意: 解方程:p ∗ e^(−x) + q ∗ sin(x) + r ∗ cos(x) + s ∗ tan(x) + t ∗ x^2 + u = 0 (0 <= x <= 1) ...
- uva:10487 - Closest Sums(二分查找)
题目:10487 - Closest Sums 题目大意:给出一组数据,再给出m个查询的数字. 要求找到这组数据里的两个数据相加的和最靠近这个查询的数据,输出那两个数据的和. 解题思路:二分查找.这样 ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- hdu2199Can you solve this equation?(解方程+二分)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- UVA 10341 Solve It 二分
题目大意:给6个系数,问是否存在X使得等式成立 思路:二分.... #include <stdio.h> #include <math.h> #define EEE 2.718 ...
- HDU 2199 Can you solve this equation?【二分查找】
解题思路:给出一个方程 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,求方程的解. 首先判断方程是否有解,因为该函数在实数范围内是连续的,所以只需使y的值满足f(0)< ...
- UVa 10341 - Solve It
题目:给一个方程,求解方程的解.已给出解的范围,并且可知方程等号左侧的函数是递减的,可用二分法进行试探,直到得出给定误差范围内的解. #include <cstdio> #include ...
随机推荐
- zoj 1453 Stripies
/* 根据题意:不难看出,要是整个方程式最小,那么应该大的数先结合,小的数后结合.先排序然后结合(贪心) */ #include<stdio.h> #include<stdlib.h ...
- spring4.1.3+springmvc+mybatis3.2.1整合
注意:这里使用了mybatis3.2.1版本,刚开始用了3.4.1的版本,会报一个很奇怪的错(java.lang.AbstractMethodError: org.mybatis.spring.tra ...
- Determine If Two Rectangles Overlap
判断相交的情况比较复杂,所以从判断不相交的角度考虑. ! (P1.y < P4.y || P1.x > P4.x || P2.y > P3.y || P2.x < P3.x)
- 常用上网增强类Chrome扩展(转)
Chrome是个非常好用的浏览器,拥有丰富的扩展资源库,能够满足网民各种各样的需求,对于网民来说,通过Chrome扩展来增强上网体验是一个基本需求,但是安装过多的扩展有容易耗费大量系统资源,今天月光博 ...
- Problem A: A + B
Problem A: A + BTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 17 Solved: 10[Submit][Status][Web Boar ...
- win7 64位 Xsheel
Xsheel5安装后,找不到.dll文件,系统支持不好,不用 Xshell4有时提示 1152:Error 就使用 链接:http://pan.baidu.com/s/1c1s42Y0 密码:098x ...
- 0603 python 基础02
作业1:ANSI和utf8的区别? ASCII是用来表示英文字符的一种编码规范,每个ASCII字符占用1个字节(8bits). 可以表示的最大字符数是256,一般只用前128个(最高位为0),其中包括 ...
- 全新安装mysql最新版本
写在前面: 下面写的东西只是最近安装的一个说明,是在系统中没存在mysql的情况下安装的,后期会根据官方文档写一个详细有价值的文档 安装原理:利用mysql官方的mysql_apt-repositor ...
- libcurl post上传文件
#include <stdio.h>#include <string.h> #include <curl/curl.h> int main(int argc, ch ...
- HDU 1286 找新朋友
题解:分析题目,就是一个裸的欧拉函数,于是AC. #include <cstdio> int eular(int n){ int ret=1,i; for(i=2;i*i<=n;i+ ...