HDU

题意:判断一个长方形是否能放到一个圆形里。

分析:将长方形的一条边贴近圆放置,求另一条边的最长长度lmax,若l<=lmax,则能放置。

注意:若这条边的长度大于直径,则一定不能放到圆里。因此,在求lmax的时候,在保证是非负数的情况下才能sqrt。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-9;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 200000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int main(){
    double r, w, l;
    int kase = 0;
    while(scanf("%lf", &r) == 1){
        if(dcmp(r, 0) == 0) return 0;
        scanf("%lf%lf", &w, &l);
        double lmax = r * r - (w / 2) * (w / 2);
        if(dcmp(l * l / 4, lmax) <= 0){
            printf("Pizza %d fits on the table.
", ++kase);
        }
        else{
            printf("Pizza %d does not fit on the table.
", ++kase);
        }
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7150039.html