BUAA 111 圆有点挤

题目描述

gg最近想给女友送两个精美的小礼品:两个底面半径分别为R1和R2的圆柱形宝石,并想装在一个盒子里送给女友。 
好不容易找到了一个长方体的盒子,其底面为A*B的矩形,他感觉好像宝石装不进去,但又不敢轻易塞进去试试。 
现请你帮他判断两个宝石能否放进盒子里(宝石只能竖直放置,且不能堆叠)。

输入

输入的第一行是一个整数,为数据的组数t(t<=1000)。 
每组数据占一行,包括4个数A,B,R1,R2,均为不超过104的正整数。

输出

对于每组数据,若两个宝石能放进盒子中,则输出YES,否则输出NO。

输入样例

2
10 10 1 1
10 10 4 4

输出样例

YES
NO

题解:判断矩形最小边是否小于两圆中最大圆的直径,小于判“NO”;然后判矩形两边减去两圆
半径后的平方和与两圆圆心距平方的大小关系,相等为两圆与矩形相切;大于为相离;小于为相交(看图比较直观)


 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 using namespace std;
13 #define lowbit(x) (x&(-x))
14 #define max(x,y) (x>y?x:y)
15 #define min(x,y) (x<y?x:y)
16 #define MAX 100000000000000000
17 #define MOD 1000000007
18 #define pi acos(-1.0)
19 #define ei exp(1)
20 #define PI 3.141592653589793238462
21 #define INF 0x3f3f3f3f3f
22 #define mem(a) (memset(a,0,sizeof(a)))
23 typedef long long ll;
24 ll gcd(ll a,ll b){
25     return b?gcd(b,a%b):a;
26 }
27 bool cmp(int x,int y)
28 {
29     return x>y;
30 }
31 const int N=10005;
32 const int mod=1e9+7;
33 int a[256];
34 int main()
35 {
36     std::ios::sync_with_stdio(false);
37     int t;
38     cin>>t;
39     while(t--){
40         int a,b,r1,r2;
41         cin>>a>>b>>r1>>r2;
42         if(2*max(r1,r2)>min(a,b)) cout<<"NO"<<endl;
43         else {
44             if((a-r2-r1)*(a-r2-r1)+(b-r2-r1)*(b-r2-r1) >= (r1+r2)*(r1+r2))
45                 cout<<"YES"<<endl;
46             else cout<<"NO"<<endl;
47         }
48     }
49     return 0;
50 }
posted @ 2017-08-01 19:16  wydxry  阅读(300)  评论(0编辑  收藏  举报
Live2D