zoukankan      html  css  js  c++  java
  • hdoj 2199 Can you solve this equation?

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2199

    解题思路:二分

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: hdoj 2199
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 #pragma comment(linker,"/STACK:1024000000,1024000000")
    26 
    27 #define lson l,m,rt<<1
    28 #define rson m+1,r,rt<<1|1
    29 ///////////////////////////////////////////////////////////////////////////
    30 
    31 ///////////////////////////////////////////////////////////////////////////
    32 const double EPS=1e-8;
    33 const double PI=acos(-1.0);
    34 
    35 const int x4[]={-1,0,1,0};
    36 const int y4[]={0,1,0,-1};
    37 const int x8[]={-1,-1,0,1,1,1,0,-1};
    38 const int y8[]={0,1,1,1,0,-1,-1,-1};
    39 ///////////////////////////////////////////////////////////////////////////
    40 
    41 ///////////////////////////////////////////////////////////////////////////
    42 typedef long long LL;
    43 
    44 typedef int T;
    45 T max(T a,T b){ return a>b? a:b; }
    46 T min(T a,T b){ return a<b? a:b; }
    47 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
    48 T lcm(T a,T b){ return a/gcd(a,b)*b; }
    49 ///////////////////////////////////////////////////////////////////////////
    50 
    51 ///////////////////////////////////////////////////////////////////////////
    52 //Add Code:
    53 double cal(double x){
    54     return 8*pow(x,4)+7*pow(x,3)+2*pow(x,2)+3*x+6;
    55 }
    56 
    57 double erfen(double y){
    58     double l=0,r=100;
    59     if(cal(l)>y || cal(r)<y) return -1;
    60     while(r-l>EPS){
    61         double m=(l+r)/2;
    62         if(cal(m)>y) r=m;
    63         else l=m;
    64     }
    65     return l;
    66 }
    67 ///////////////////////////////////////////////////////////////////////////
    68 
    69 int main(){
    70     ///////////////////////////////////////////////////////////////////////
    71     //Add Code:
    72     int Case;
    73     double y;
    74     scanf("%d",&Case);
    75     while(Case--){
    76         scanf("%lf",&y);
    77         double x=erfen(y);
    78         if(x==-1) printf("No solution!
    ");
    79         else printf("%.4lf
    ",x);
    80     }
    81     ///////////////////////////////////////////////////////////////////////
    82     return 0;
    83 }
    84 
    85 ///////////////////////////////////////////////////////////////////////////
    86 /*
    87 Testcase:
    88 Input:
    89 2
    90 100
    91 -4
    92 Output:
    93 1.6152
    94 No solution!
    95 */
    96 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    java注解-笔记
    java重载与重写-笔记
    java中(equals与==)- 笔记
    Java迭代与递归-笔记
    C++指针悬挂-笔记
    极速倒入sql记录到excel表格,19个子段5万条记录只需30秒
    利用MCI的方法可以方便的实现光驱门的开关
    如何让你的程序在任务列表隐藏
    如何实现遍历文件夹中的所有文件
    识别操作系统版本
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3317561.html
Copyright © 2011-2022 走看看