zoukankan      html  css  js  c++  java
  • [二分] [计算几何] AtCoder Beginner Contest 144 D Water Bottle

    题意:给定一底面积为正方形的方体并装入x体积的水,问最大倾斜角度使得水不流出

    如图所示只有两种情况且面积具有单调性 二分求解即可

    /*
        Zeolim - An AC a day keeps the bug away
    */
      
    //#pragma GCC optimize(2)
    //#pragma GCC ("-W1,--stack=128000000")
    #include <bits/stdc++.h>
    using namespace std;
    #define mp(x, y) make_pair(x, y)
    #define fr(x, y, z) for(int x = y; x < z; ++x)
    #define pb(x) push_back(x)
    #define mem(x, y) memset(x, y, sizeof(x))
    typedef long long ll;
    typedef unsigned long long ull;
    typedef long double ld;
    typedef std::pair <int, int> pii;
    typedef std::vector <int> vi;
    void re(ll &x){x=0;char s=getchar();while(s<'0'||s>'9')s=getchar();while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}}
    void wr(ll x){if(x>9) wr(x/10);putchar(x%10+'0');}
    const ld PI = acos(-1.0);
    const ld E = exp(1.0);
    const ll INF = 0x3f3f3f3f3f3f3f3f;
    const ll MOD = 386910137;
    const ull P = 13331;
    const int MAXN = 1e6 + 100;
     
    ld a, b, x, y;
     
    ld to(ld x) { return (x / 180.0) * PI; }
    ld ret(ld x) { return x / PI * 180.0; }
     
    ld cal(ld deg)
    {
    	if(deg >= y)
    	{
    		ld rb = a * tan(PI / 2.0 - deg) ;
    		return a * b * a - a * rb / 2.0 * a;
    	}
    	else
    	{
    		ld ra = b * tan(deg);
    		return (b * ra / 2.0 * a);
    	}
    }
     
     
    int main()
    {  
        //ios::sync_with_stdio(0);
        //cin.tie(0); cout.tie(0);
        //freopen("d:out.txt","w",stdout);
        //freopen("d:in.txt","r",stdin);  
      	
      	cin >> a >> b >> x;
      	
      	y = atan(a/b);
      	
      	ld fst = 0, lst = PI / 2.0, mid;
      	
      	for(int i = 0; i < 1000; ++i)
      	{
      		mid = (fst + lst) / 2.0;
      		
      		if(cal(mid) >= x)
      			lst = mid;
      		else
      			fst = mid;
    	}
    	  
    	cout << fixed << setprecision(10) << 90.0 - mid / PI * 180.0 << '
    ';
        
        return 0;
    }
    
  • 相关阅读:
    【Java】LinkedHashMap
    【Java】 HashMap
    【译】Solr in Action 第三章
    【译】Solr in Action 第二章
    【译 】Solr in Action 第一章
    【Three.js】OrbitControl 旋转
    【翻译】JNA调用DLL
    .Net使用Redis详解之ServiceStack.Redis
    C#操作redis
    ECharts图介绍
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270321.html
Copyright © 2011-2022 走看看