K - Table(思维题+数学知识)

在这里插入图片描述

There are 4 bars, possibly, having different lengths. Can they be used as the legs of the table, such that:

The legs stay vertically in the vertices of some rectangle;
The surface of the table, possibly, sloping, touches all four legs?

Input
The input contains 4 integers a1, a2, a3, a4 (1≤ai≤109) — the lengths of the bars.

Output
Output “YES” or “NO”, depending on it is possible to make a table with the given design or not.

题解:看矩形对角线桌角和是否相同,如果相同则输出YES,反之输出NO

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long int a[5];
    for(int i = 0;i<4;i++)
        cin>>a[i];
    sort(a,a+4);
    if((a[0]+a[3])==(a[1]+a[2]))
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}
发布了65 篇原创文章 · 获赞 2 · 访问量 822

猜你喜欢

转载自blog.csdn.net/weixin_43797452/article/details/105522365