From 91ca20b8f78eeeb74fc4eea6eeecdca9fefa5656 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Tue, 1 Nov 2022 11:51:53 +0200 Subject: Added new problems --- codechef/ShortestPathInBinaryTrees/main | Bin 0 -> 22544 bytes codechef/ShortestPathInBinaryTrees/main.cpp | 24 +++++++++++++++++++++ codechef/ShortestPathInBinaryTrees/main_input0.txt | 4 ++++ .../ShortestPathInBinaryTrees/main_output0.txt | 3 +++ 4 files changed, 31 insertions(+) create mode 100755 codechef/ShortestPathInBinaryTrees/main create mode 100644 codechef/ShortestPathInBinaryTrees/main.cpp create mode 100644 codechef/ShortestPathInBinaryTrees/main_input0.txt create mode 100644 codechef/ShortestPathInBinaryTrees/main_output0.txt (limited to 'codechef/ShortestPathInBinaryTrees') diff --git a/codechef/ShortestPathInBinaryTrees/main b/codechef/ShortestPathInBinaryTrees/main new file mode 100755 index 0000000..1b29c37 Binary files /dev/null and b/codechef/ShortestPathInBinaryTrees/main differ diff --git a/codechef/ShortestPathInBinaryTrees/main.cpp b/codechef/ShortestPathInBinaryTrees/main.cpp new file mode 100644 index 0000000..eb5f641 --- /dev/null +++ b/codechef/ShortestPathInBinaryTrees/main.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--){ + int i, j; + cin >> i >> j; + int ans = 0; + while(i != j) { + if (j > i) { + j /= 2; + } else { + i /= 2; + } + ans++; + } + cout << ans << '\n'; + } +} diff --git a/codechef/ShortestPathInBinaryTrees/main_input0.txt b/codechef/ShortestPathInBinaryTrees/main_input0.txt new file mode 100644 index 0000000..94da79c --- /dev/null +++ b/codechef/ShortestPathInBinaryTrees/main_input0.txt @@ -0,0 +1,4 @@ +3 +1 2 +2 3 +4 3 diff --git a/codechef/ShortestPathInBinaryTrees/main_output0.txt b/codechef/ShortestPathInBinaryTrees/main_output0.txt new file mode 100644 index 0000000..01e79c3 --- /dev/null +++ b/codechef/ShortestPathInBinaryTrees/main_output0.txt @@ -0,0 +1,3 @@ +1 +2 +3 -- cgit v1.2.3