NC232085. Rain_w and Equation
描述
输入描述
The first line contains a single integer -the number of equations.
Next lines, the i-th line contains four integers separated by space. It is guaranteed that . And it can be proved that the solutions satisfied the conditions are always existed.
输出描述
The output should contains lines. The i-th line should contains two integers separated by space. If it has multiple solutions, you can print any of them.
示例1
输入:
3 1 1 1 2 1 2 3 4 19 26 8 17
输出:
3 1 10 5 470 381
C 解法, 执行用时: 13ms, 内存消耗: 668K, 提交时间: 2022-01-11 09:24:58
#include<stdio.h> #include<math.h> int main() { int t,i; long long e,f,a,b,c,d; scanf("%d",&t); for(i=0;i<t;i++){ scanf("%lld %lld %lld %lld",&a,&b,&c,&d); e=llabs(a*c-b*d); f=(a*d+b*c); if(e==0){ e=llabs(a*d-b*c); f=(a*c+b*d); } printf("%lld %lld\n",e,f); } return 0; }
C++ 解法, 执行用时: 49ms, 内存消耗: 776K, 提交时间: 2022-01-26 15:50:27
#include<bits/stdc++.h> using namespace std; long long T,a,b,c,d; int main() { cin>>T; while(T--) { cin>>a>>b>>c>>d; if(a*d-b*c!=0) cout<<a*c+b*d<<' '<<abs(a*d-b*c)<<endl; else cout<<abs(a*c-b*d)<<' '<<a*d+b*c<<endl; } }
Python3 解法, 执行用时: 159ms, 内存消耗: 4980K, 提交时间: 2022-01-15 15:44:00
for _ in range(int(input())): a,b,c,d=map(int,input().split()) if(b*c==a*d): print(abs(b*c+a*d),abs(a*c-b*d)) else: print(abs(b*c-a*d),abs(a*c+b*d))