Can you solve this equation?---hdu2199(二分)
2015-09-04 13:56
330 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2199
给出y的值求x;
8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 = Y
x是0到100的实数所以要用二分的方法;
View Code
给出y的值求x;
8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 = Y
x是0到100的实数所以要用二分的方法;
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <queue> using namespace std; #define N 110 #define INF 0xffffff int main() { int T,flag; double y, m, L, R, Mid; scanf("%d", &T); while(T--) { scanf("%lf", &y); m=8*pow(100,4)+7*pow(100,3)+2*pow(100,2)+3*100+6; if(m<y||y<6) { printf("No solution!\n"); continue; } L=0;R=100; while(L<=R) { Mid=(L+R)/2; m=8*pow(Mid,4)+7*pow(Mid,3)+2*pow(Mid,2)+3*Mid+6; if(fabs(m-y)<0.0001) { flag=1; break; } else if(m>y) { R=Mid; } else { L=Mid; } } if(flag==1) printf("%.4lf\n", Mid); else printf("No solution!\n"); } return 0; }
View Code
相关文章推荐
- JDK,SDK,API之间的概念汇总
- DP水一水
- 命令模式
- zabbix_agent反复报警-日志显示“first network error”的问题
- 在CUDA项目中使用ctags
- Linux C语言程序设计(十六)——TCP/IP协议基本解析
- 验证码识别<1>
- Codeforces 460C Present
- 学习方法
- C语言中链表任意位置怎么插入数据?然后写入文件中?
- C语言中链表任意位置怎么插入数据?然后写入文件中?
- 再探设计模式之状态模式(纸牌游戏的开发)
- NOIP2014飞扬的小鸟
- PCMCIA卡知识
- MySQL 实现树形的遍历(关于多级菜单栏以及多级上下部门的查询问题)
- Codeforces 466B Wonder Room
- Team Queue (uva540 队列模拟)
- 黑马程序员——Objective-C之面向对象基础
- IOS基础UI之(四)汤姆猫的实现
- Team Queue (uva540 队列模拟)