Minimal Square

举报
辰chen 发表于 2022/06/24 01:05:39 2022/06/24
【摘要】 文章目录 一、A. Minimal Square总结 一、A. Minimal Square 本题链接:A. Minimal Square 题目: A. Minimal Squar...


一、A. Minimal Square

本题链接A. Minimal Square

题目

A. Minimal Square

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output

Find the minimum area of a square land on which you can place two identical rectangular a×b houses. The sides of the houses should be parallel to the sides of the desired square land.

Formally,

You are given two identical rectangles with side lengths a and b (1≤a,b≤100) — positive integers (you are given just the sizes, but not their positions).
Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square.
Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.

在这里插入图片描述
Input
The first line contains an integer t (1≤t≤10000) —the number of test cases in the input. Then t test cases follow.

Each test case is a line containing two integers a, b (1≤a,b≤100) — side lengths of the rectangles.

Output
Print t answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions a×b.

Example
input
8
3 2
4 2
1 1
3 1
4 7
1 3
7 4
100 100
output
16
16
4
9
64
9
64
40000

Note
Below are the answers for the first two test cases:
在这里插入图片描述

本博客给出本题截图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

题意t组数据,每次数据给一个长方形的长和宽,现在把两个 相同 的长方形放入到一个正方形内部,可以旋转长方形但旋转必须满足长方形的边和正方形的边相平行,两个正方形不可以重叠,求正方形面积最小值

AC代码

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;
    
    while (t -- )
    {
        int l, r;
        cin >> l >> r;
        
        if (l < r)
            swap(l, r);
        int len = max(r * 2, l);
            
        cout << len * len << endl;
    }
    
    return 0;
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

总结

水题,不解释

文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。

原文链接:chen-ac.blog.csdn.net/article/details/118999813

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。