SDUT 2022 Spring Individual Contest(for 21) - 6 - Virtual Judge
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 a_1a1, a_2a2, a_3a3, a_4a4 (1 \le a_i \le 10^91≤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.
Sample 1
Inputcopy | Outputcopy |
---|---|
1 1 1 1 | YES |
Sample 2
Inputcopy | Outputcopy |
---|---|
1 5 1 5 | YES |
Sample 3
Inputcopy | Outputcopy |
---|---|
1 3 2 2 | YES |
Sample 4
Inputcopy | Outputcopy |
---|---|
9 5 11 8 | NO |
题意:给定一个桌子的四个桌脚的长度,判断这四个桌脚能否恰好保证支撑起这个桌子(即保证桌面是一个平面)。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[5];
for(int i=0;i<4;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+4);
if(a[1]-a[0]==a[3]-a[2])
printf("YES\n");
else
printf("NO\n");
}
别人的题解:
设这四根桌脚的长度分别为 a0,a1,a2,a3。a0,a1,a2,a3 (从小到大排列),如果 ABCDABCD 为一平面,则必须满足:
|DM|=|CN|⇔a3-a1=a2-a0
面CBAD是一个面--->CB==AD-->三角形CBN与三角形DMA全等