Can you solve this equation?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7156    Accepted Submission(s): 3318

Problem Description

Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,can you find its solution between 0 and 100;
Now please try your lucky.

Input

The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has a real number Y (fabs(Y) <= 1e10);

Output

For each test case, you should just output one real number(accurate up to 4 decimal places),which is the solution of the equation,or “No solution!”,if there is no solution for the equation between 0 and 100.

Sample Input

2
100
-4

Sample Output

1.6152
No solution!

::很容易知道y=8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 单调递增,那么我们就可以对[0,100]进行二分搜索,找出满足条件的数

代码:

    #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
double f(double x){
return 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6;
} int main()
{
int T,y;
scanf("%d",&T);
while (T--)
{
scanf("%d",&y);
if( f(0) > y || f(100) < y) //f(0)>y或f(100)<y则无解
{
printf("No solution!\n");
continue;
}
double l = 1.0, r = 100.0;
while( r - l > 1e-6)
{
double m=(l+r)/2;
if(f(m)>y) r=m-1e-7;
else l=m+1e-7;
}
printf("%.4lf\n",(l+r)/2);
}
return 0;
}

hdu 2199 Can you solve this equation?(二分搜索)的更多相关文章

  1. HDU 2199 Can you solve this equation?(二分精度)

    HDU 2199 Can you solve this equation?     Now,given the equation 8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == ...

  2. hdu 2199 Can you solve this equation?(高精度二分)

    http://acm.hdu.edu.cn/howproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/1000 MS ...

  3. HDU 2199 Can you solve this equation?(二分解方程)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2199 Can you solve this equation? Time Limit: 2000/10 ...

  4. hdu 2199:Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  5. ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分

    Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  6. HDU 2199 Can you solve this equation? (二分 水题)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  7. HDU 2199 Can you solve this equation(二分答案)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  8. HDU - 2199 Can you solve this equation? 二分 简单题

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. hdu 2199 Can you solve this equation? 二分

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

随机推荐

  1. 关于window.onload,window.onbeforeload与window.onunload

    ★  window.onload  当页面加载完毕的时候执行,即在当前页面进行其他操作之前执行.如,刚进入某个网页的弹窗提示. (  与window.onload相近的可以参考我写的另外一篇记录&qu ...

  2. 将HTML5 Canvas的内容保存为图片

    主要思想是借助Canvas自己的API - toDataURL()来实现,整个实现 HTML + JavaScript的代码很简单. 代码如下: <html> <meta http- ...

  3. asp.net.mvc 的单文件上传和多文件上传的简单例子

    首先打开vs2012,创建空的mvc4项目,名称为MVCStudy,选择基本模板

  4. css中inline、block、inline-block的区别

    http://www.cnblogs.com/fxair/archive/2012/07/05/2577280.html display:inline就是将元素显示为块级元素. block元素的特点是 ...

  5. php实现添加图片水印

    实际运行时需要开启php 的gd2功能,运行环境php4.0以上(demo中的路径改为实际路径) <?php/*打开图片*/ //1.配置图片路径 $src="image/61.jpg ...

  6. ASP.NET Web API获取Model元数据

    using System; using System.Web.Http; using Common; namespace ConsoleApp { internal class Program { p ...

  7. Java中的GOF23(23中设计模式)--------- 工厂模式(Factory)

    Java中的GOF23(23中设计模式)--------- 工厂模式(Factory) 在给大家介绍工厂模式之前,我想和大家聊聊面向对象的那点事,在这里,引入三个概念. 开闭原则(Open Close ...

  8. Atitit.为什么小公司也要做高大上开源项目

    Atitit.为什么小公司也要做高大上开源项目 1. 为什么手头有很多加急的事情还要做高大上开源项目??1 2. 从长远看,发展 高大上开源项目计划对于解决我们在应急项目正面临着的种种严峻问题也大有裨 ...

  9. SharePoint 2010: Nailing the error "The Security Token Service is unavailable"

    http://blogs.technet.com/b/sykhad-msft/archive/2012/02/25/sharepoint-2010-nailing-the-error-quot-the ...

  10. mac svn client 设置

    经过谷歌和百度N次后,终于搞定SVN的升级,Intellij Idea和Xcode5.1都可以正常使用. 步骤: 1. 下载Subverion的Max安装版.(推荐.使用其他brew和port都试过, ...