zoukankan      html  css  js  c++  java
  • uva 10341 Solve It

    解题思路:二分

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: uva 10341
     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 const double E=2.7182818284590452353602874713526;
    35 
    36 const int x4[]={-1,0,1,0};
    37 const int y4[]={0,1,0,-1};
    38 const int x8[]={-1,-1,0,1,1,1,0,-1};
    39 const int y8[]={0,1,1,1,0,-1,-1,-1};
    40 ///////////////////////////////////////////////////////////////////////////
    41 
    42 ///////////////////////////////////////////////////////////////////////////
    43 typedef long long LL;
    44 
    45 typedef int T;
    46 T max(T a,T b){ return a>b? a:b; }
    47 T min(T a,T b){ return a<b? a:b; }
    48 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
    49 T lcm(T a,T b){ return a/gcd(a,b)*b; }
    50 ///////////////////////////////////////////////////////////////////////////
    51 
    52 ///////////////////////////////////////////////////////////////////////////
    53 //Add Code:
    54 int p,q,r,s,t,u;
    55 
    56 double cal(double x){
    57     double ret=p*pow(E,-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*x*x+u;
    58     return ret;
    59 }
    60 
    61 double erfen(){
    62     double l=0,r=1;
    63     if(cal(0)<0 || cal(1)>0) return -1;
    64     while(r-l>EPS){
    65         double m=(l+r)/2,temp=cal(m);
    66         if(fabs(temp)<EPS) return m;
    67         if(temp<0) r=m;
    68         else l=m;
    69     }
    70     return l;
    71 }
    72 ///////////////////////////////////////////////////////////////////////////
    73 
    74 int main(){
    75     ///////////////////////////////////////////////////////////////////////
    76     //Add Code:
    77     while(scanf("%d%d%d%d%d%d",&p,&q,&r,&s,&t,&u)!=EOF){
    78         double x=erfen();
    79         if(x==-1) printf("No solution
    ");
    80         else printf("%.4lf
    ",x);
    81     }
    82     ///////////////////////////////////////////////////////////////////////
    83     return 0;
    84 }
    85 
    86 ///////////////////////////////////////////////////////////////////////////
    87 /*
    88 Testcase:
    89 Input:
    90 0 0 0 0 -2 1
    91 1 0 0 0 -1 2
    92 1 -1 1 -1 -1 1
    93 Output:
    94 0.7071
    95 No solution
    96 0.7554
    97 */
    98 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    SQL Server, Timeout expired.all pooled connections were in use and max pool size was reached
    javascript 事件调用顺序
    Best Practices for Speeding Up Your Web Site
    C语言程序设计 使用VC6绿色版
    破解SQL Prompt 3.9的几步操作
    Master page Path (MasterPage 路径)
    几个小型数据库的比较
    CSS+DIV 完美实现垂直居中的方法
    由Response.Redirect引发的"Thread was being aborted. "异常的处理方法
    Adsutil.vbs 在脚本攻击中的妙用
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3325206.html
Copyright © 2011-2022 走看看