Cyclic Quadrilateral
Hazrat Ali
Read problem statements in Mandarin Chinese, Russian, and Vietnamese as well.
You are given the sizes of angles of a simple quadrilateral (in degrees) A, B, C and D, in some order along its perimeter. Determine whether the quadrilateral is cyclic.
Note: A quadrilateral is cyclic if and only if the sum of opposite angles is 180∘.
Input
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains four space-separated integers A, B, C and D.
Output
Print a single line containing the string "YES"
if the given quadrilateral is cyclic or "NO"
if it is not (without quotes).
You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
Constraints
- 1≤T≤104
- 1≤A,B,C,D≤357
- A+B+C+D=360
Sample 1:
3 10 20 30 300 10 20 170 160 179 1 179 1
NO YES NO
Solution
def power(x, y, MOD=float('inf')):
if y == 0:
return 1
if y % 2 == 0:
return power((x * x) % MOD, y // 2, MOD) % MOD
else:
return (x * power((x * x) % MOD, (y - 1) // 2, MOD)) % MOD
def main():
t = int(input())
for _ in range(t):
a, b, c, d = map(int, input().split())
if a + c == 180 and b + d == 180:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()