首页 > 代码库 > HDU - 2368 Alfredo's Pizza Restaurant
HDU - 2368 Alfredo's Pizza Restaurant
题意:判断一个长方形是否能放到一个圆形里。
分析:将长方形的一条边贴近圆放置,求另一条边的最长长度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.\n", ++kase); } else{ printf("Pizza %d does not fit on the table.\n", ++kase); } } return 0;}
HDU - 2368 Alfredo's Pizza Restaurant
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。