ধরুন, একটি বিল্ডিং আছে যার কেন্দ্র স্থানাঙ্ক xc, yc এবং উচ্চতা h আছে। আমরা বিল্ডিংয়ের কেন্দ্র স্থানাঙ্কগুলি জানি না, তবে আমাদেরকে n টুকরো তথ্য সরবরাহ করা হয়েছে যাতে x এবং y স্থানাঙ্ক এবং একটি উচ্চতা মান a রয়েছে৷ স্থানাঙ্কের উচ্চতা (x, y) সর্বাধিক (h - |x - xc| - |y - yc|, 0)। আমাদের কেন্দ্রের স্থানাঙ্ক এবং বিল্ডিংয়ের উচ্চতা খুঁজে বের করতে হবে। কোঅর্ডিনেট xi দেওয়া হয় অ্যারে x-এ, yi দেওয়া হয় teg অ্যারে y, এবং ai দেওয়া হয় অ্যারে অ্যারে।
সুতরাং, যদি ইনপুটটি n =3, x ={3, 3, 2}, y ={4, 2, 3}, a ={6, 6, 6} এর মত হয়, তাহলে আউটপুট হবে 3 3 7।
কেন্দ্রের স্থানাঙ্কগুলি হল 3,3 এবং বিল্ডিংয়ের উচ্চতা হল 7৷
৷পদক্ষেপ
এটি সমাধান করতে, আমরা এই পদক্ষেপগুলি অনুসরণ করব -
check := true for initialize xc := 0, when xc <= 100, update (increase xc by 1), do: for initialize yc := 0, when yc <= 100, update (increase yc by 1), do: check := true mh := 2000000000 h := -1 for initialize i := 0, when i < n, update (increase i by 1), do: k := |(x[i] - xc) + |y[i] - yc|| if a[i] is same as 0, then: mh := minimum of mh and k else: if h < 0, then: h := a[i] + k otherwise when h is not equal to a[i] + k, then: check := false Come out from the loop if h > mh, then: check := false Ignore following part, skip to the next iteration if check is non-zero, then: Come out from the loop if check is non-zero, then: Come out from the loop print(xc, yc, h)
উদাহরণ
আরো ভালোভাবে বোঝার জন্য আসুন নিচের বাস্তবায়ন দেখি -
#include <bits/stdc++.h>
using namespace std;
void solve(int n, vector<int> x, vector<int> y, vector<int> a){
bool check = true;
int xc, yc, h;
for (xc = 0; xc <= 100; xc++) {
for (yc = 0; yc <= 100; yc++) {
check = true;
int k, mh = 2e9;
h = -1;
for(int i = 0; i < n; i++) {
k = abs(x[i] - xc) + abs(y[i] - yc);
if (a[i] == 0) {
mh = min(mh, k);
} else {
if (h < 0) {
h = a[i] + k;
} else if (h != a[i] + k) {
check = false;
break;
}
}
}
if (h > mh) {
check = false;
continue;
}
if (check) {
break;
}
}
if (check) {
break;
}
}
cout << xc << " " << yc << " " << h;
}
int main() {
int n = 3;
vector<int> x = {3, 3, 2}, y = {4, 2, 3}, a = {6, 6, 6};
solve(n, x, y, a);
return 0;
} ইনপুট
3, {3, 3, 2}, {4, 2, 3}, {6, 6, 6} আউটপুট
3 3 7