列表

详情


NC15423. 李老师划分田地

描述

李老师在麦田里行走,脑海中闪过一个念头,这个麦田有我自己家的麦田大吗?这里的大不是单纯指面积大。李老师家的麦田长为a,宽为b,想象成一个矩形C;另一家麦田的长为x,宽为y,想象成一个矩形D。李老师,麻烦你给他判定下,矩形D是否能够放入矩形C。注意两矩形边界不能重合。

输入描述

第一行输入一个整数T,接下来有T行;
输入四个整数A, B, X, Y ;
1 <= A, B, X, Y <= 50000

输出描述

如果矩形D能够放入C,请输出“Escape is possible.”(注意输出不带双引号)
反之直接输出“Box cannot be dropped.”

示例1

输入:

3
9 9 8 8
8 8 9 9
3 3 3 3

输出:

Escape is possible.
Box cannot be dropped.
Box cannot be dropped.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 480K, 提交时间: 2019-04-10 20:54:55

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int a,b,x,y;
bool judge()
{
    if(a*b<=x*y)return false;
    if(a>x&&b>y)return true;
    if(b<=y)return false;
    double angle1,angle2,angle3,length,djx;
    djx=sqrt(x*x+y*y);
    angle1=acos(y*1.0/djx);
    angle2=acos(b*1.0/djx);
    angle3=angle1-angle2;
    length=djx*sin(angle2)+2*y*sin(angle3);
    if(length<a)return true;
    else return false;
}
int main()
{
    int T;
    //freopen("6.in","r",stdin);
    //freopen("6.out","w",stdout);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&a,&b,&x,&y);
        if(b>a)
        {
            swap(a,b);
        }
        if(y>x)
        {
            swap(x,y);
        }
        if(judge())printf("Escape is possible.\n");
        else printf("Box cannot be dropped.\n");
    }
    return 0;
}

C++(clang++ 11.0.1) 解法, 执行用时: 4ms, 内存消耗: 384K, 提交时间: 2023-07-22 01:23:53

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void solve() {
	int a, b, x, y;
	cin >> a >> b >> x >> y;

	if (a < b) {
		swap(a, b);
	}
	if (x < y) {
		swap(x, y);
	}
    
	bool vaild = x < a && y < b && x * y < a * b;
	cout << (vaild ? "Escape is possible." : "Box cannot be dropped.") << "\n";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t;
	for (cin >> t; t; -- t) {
		solve();
	}


	return 0;
}

上一题