YT14-HDU-盒子与瓷砖

Problem Description

There is a large room in the Pyramid called Room-of-No-Return. Its floor is covered by rectangular tiles of equal size. The name of the room was chosen because of the very high number of traps and mechanisms in it. The ACM group has spent several years studying
the secret plan of this room. It has made a clever plan to avoid all the traps. A specially trained mechanic was sent to deactivate the most feared trap called Shattered Bones. After deactivating the trap the mechanic had to escape from the room. It is very
important to step on the center of the tiles only; he must not touch the edges. One wrong step and a large rock falls from the ceiling squashing the mechanic like a pancake. After deactivating the trap, he realized a horrible thing: the ACM plan did not take
his equipment box into consideration. The box must be laid onto the ground because the mechanic must have both hands free to prevent contact with other traps. But when the box is laid on the ground, it could touch the line separating the tiles. And this is
the main problem you are to solve.

Input

The input consists of T test cases. The number of them (T) is given on the first line of the input. Each test case consists of a single line. The line contains exactly four integer numbers separated by spaces: A, B, X and Y. A and Bindicate the dimensions of
the tiles, X and Y are the dimensions of the equipment box (1 <= A, B, X, Y <= 50000).

Output

Your task is to determine whether it is possible to put the box on a single tile -- that is, if the whole box fits on a single tile without touching its border. If so, you are to print one line with the sentence "Escape is possible.". Otherwise print the sentence
"Box cannot be dropped.".

Sample Input

2
10 10 8 8
8 8 10 10

Sample Output

Escape is possible.
Box cannot be dropped.

代码如下:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        double a, b, n, m, temp;
        cin>>a>>b>>n>>m;
        if(a > b)
        {
            temp = a;
            a = b;
            b = temp;
        }
        if(n > m)
        {
            temp = n;
            n = m;
            m = temp;
        }
        double x, y;
        if(a >= n && b >= m)
        {
            cout<<"Escape is possible."<<endl;
            continue;
        }
        else if((n > a && m > b) || (n > a && m < b))
        {
            cout<<"Box cannot be dropped."<<endl;
            continue;
        }
        else
        {
            double c = sqrt(a * a + b * b);
            if(c <= m)
            {
                cout<<"Box cannot be dropped."<<endl;
                continue;
            }
            y = ((2 * a * n * n + sqrt((-4) * n * n * m * m *(a * a - m * m - n * n)))) / (2 * (n * n + m * m));
            x = sqrt(n * n - y * y);
            if(b - sqrt( m * m - (a - y) * (a - y)) >= x)
            {
                cout<<"Escape is possible."<<endl;
            }
            else
                cout<<"Box cannot be dropped."<<endl;
        }
    }
    return 0;
}

两个矩形的包容问题。

时间: 02-06

YT14-HDU-盒子与瓷砖的相关文章

HDU 5810 Balls and Boxes(盒子与球)

HDU 5810 Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment

hdu 2501 Tiling_easy version 递推

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2501 题目分析:已知有2*1,2*2,两种型号的瓷砖,要求铺满2*n的格子有多少种方法.可以考虑最左边一列的铺法,竖着铺的话,右边为f(n-1),只有一种铺法:横着铺的话,可以用一块2*2或者两块2*1的横铺, 右边为f(n-2), 有两种. 故递推公式为:f(n) = f(n-1) + 2*f(n-2) /*Tiling_easy version Time Limit: 1000/1000 MS

HDU 4704 欧拉定理

题目看了很久没看懂 就是给你数n,一种函数S(k),S(k)代表把数n拆成k个数的不同方案数,注意如n=3,S(2)是算2种的,最后让你求S(1~n)的和模1e9+7,n<=1e100000.那么其实一个S(k)就是把n个小球放到k-1个盒子里的种类数,求和也就是求个$2^{n-1}$. n超大,但是模数只有1e9+7,用欧拉定理就行了. /** @Date : 2017-09-12 18:41:59 * @FileName: HDU 4704 欧拉定理 降幂.cpp * @Platform:

排列组合+组合数取模 HDU 5894

1 // 排列组合+组合数取模 HDU 5894 2 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 3 // 思路: 4 // 定好m个人 相邻人之间k个座位 剩下就剩n-(m+1)*k个座位 5 // 剩下座位去插m个不同的盒子==就等价n个相同的球放m个不同的盒子 6 // 然后组合数出来了 7 // 乘n的话是枚举座位,除m是去掉枚举第一个座位的时候,剩下人相邻的座位相对不变的情况 8 9 #include <iostream> 10 #incl

hdu 5463 Clarke and minecraft

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5463 Clarke and minecraft Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 366    Accepted Submission(s): 193 Problem Description Clarke is a patien

HDU 1561&amp;HDU 3449 一类简单依赖背包问题

HDU 1561.这道是树形DP了,所谓依赖背包,就是选A前必须选B,这样的问题.1561很明显是这样的题了.把0点当成ROOT就好,然后选子节点前必须先选根,所以初始化数组每一行为该根点的值.由于多选了0点,所以记得把m++. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN=22

HDU 2643 Rank:第二类Stirling数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2643 题意: 有n个个选手参赛,问排名有多少种情况(可以并列). 题解: 简化问题: 将n个不同的元素放到i个有差别的盒子中,情况数为P(n,i),求∑P(n,i) (1<=i<=n) 再简化: 将n个不同的元素放到i个无差别的盒子中,情况数为S(n,i),求∑( S(n,i)*i! ) (1<=i<=n) 哇这是第二类Stirling数 ( ̄▽ ̄)~* 递推式:s(n,k) = s(

hdu 4710 Balls Rearrangement (数学思维)

题意:就是  把编号从0-n的小球对应放进i%a编号的盒子里,然后又买了新盒子, 现在总共有b个盒子,Bob想把球装进i%b编号的盒子里.求重置的最小花费. 每次移动的花费为y - x ,即移动前后盒子编号的差值的绝对值. 算法: 题目就是要求                  先判断  n与  lcm(a,b)的大小,每一个周期存在循环,这样把区间缩短避免重复计算. 如果n>lcm(a,b)则   ans = (n/lcm)*solve(lcm)+solve(n%lcm) 否则   ans =

【HDU】Card Collector

http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:n张卡片,每一次取一个盒子,盒子里装有卡片i的概率是p[i],求得到所有卡片所需要开的盒子的期望数(n<=20) #include <cstdio> #include <cstring> using namespace std; const int N=22; int n; double p[N], f[1<<N]; int main() { while(~scan

BestCoder17 1001.Chessboard(hdu 5100) 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5100 题目意思:有一个 n * n 的棋盘,需要用 k * 1 的瓷砖去覆盖,问最大覆盖面积是多少. 比赛时不会做............. hdu 题解: 首先,若n<k,则棋盘连一个1×k的矩形都放不下,输出0. 我们只需要考虑n≥k的情况.将棋盘类似于黑白染色,按(i+j)模k划分等价类,给每个格子标一个号. 标号之后,会注意到每条从左下到右上的斜线数字都是相同的,那么对于s×s的格子,其内部