Untitled
unknown
c_cpp
a year ago
2.2 kB
15
Indexable
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define mat vector<vector<ll>>
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define SZ(a) (int) a.size()
using namespace std;
void db() {cout << '\n';}
template <typename T, typename ...U> void db(T a, U ...b) {
cout << a << ' ', db(b...);}
#ifdef Cloud
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define file ios::sync_with_stdio(false); cin.tie(0)
#endif
const int inf = 1ll << 61, N = 2005, mod = 1e9 + 7, INF = 1ll << 61;
void solve(){
int n; cin >> n;
vector<pii> a(n), b(n);
for(int i = 0; i < n; ++i){
cin >> a[i].fi >> a[i].se;
}
for(int i = 0; i < n; ++i){
cin >> b[i].fi >> b[i].se;
}
sort(ALL(a));
sort(ALL(b));
if(b[0].fi == b[n - 1].fi and b[0].se == b[n - 1].se){
db(0, b[0].fi, b[0].se);
return;
}
int dbx = b[n - 1].fi - b[0].fi, dax = a[n - 1].fi - a[0].fi;
int fx = 0, fy = 0, S = -1, X = -1, Y = -1;
if(dbx == 0 and dax == 0){
fx = 1;
}
else if(dbx == 0 or dax == 0 or (dbx % dax) != 0){
db(-1);
return;
}
else{
S = dbx / dax;
X = b[0].fi - S * a[0].fi;
}
int dby = b[n - 1].se - b[0].se, day = a[n - 1].se - a[0].se;
if(dby == 0 and day == 0) fy = 1;
else if(dby == 0 or day == 0 or (dby % day) != 0){
db(-1);
return;
}
else{
if(S != -1 and S != (dby / day)){
db(-1);
return;
}
S = dby / day;
Y = b[0].se - S * a[0].se;
}
if(fx == 1 and fy == 1){
S = 0, X = b[0].fi, Y = b[0].se;
}
else if(fx == 1){
X = b[0].fi - S * a[0].fi;
}
else if(fy == 1){
Y = b[0].se - S * a[0].se;
}
for(int i = 0; i < n; ++i){
int x = a[i].fi * S + X;
int y = a[i].se * S + Y;
if(x != b[i].fi or y != b[i].se){
db(-1);
return;
}
}
db(S, X, Y);
}
signed main(){
file;
int t = 1;
// cin >> t;
while (t--) solve();
}Editor is loading...
Leave a Comment