From a20b54c03ac686eff7dae1250f0f0a2e4c65fbda Mon Sep 17 00:00:00 2001 From: Satvinder31415 <53083658+Satvinder31415@users.noreply.github.com> Date: Mon, 23 Dec 2019 14:08:13 +0530 Subject: [PATCH 1/2] Add files via upload --- STABLEMP.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 STABLEMP.cpp diff --git a/STABLEMP.cpp b/STABLEMP.cpp new file mode 100644 index 0000000..4be1fc4 --- /dev/null +++ b/STABLEMP.cpp @@ -0,0 +1,81 @@ +#include +#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); + +using namespace std; + + vector stableMariage(vector> &menPref, vector> &womenPref) +{ + int n = menPref.size(); + vector> mapWM(n); + for (int i = 0; i < n; ++i) + mapWM[i].resize(n); + for (int i = 0; i < n; ++i) + for (int j = 0; j < n; ++j) + mapWM[i][ womenPref[i][j] ] = j; + vector womanMatch(n, -1); + vector manMatch(n, -1); + queue q; + for (int i = 0; i < n; ++i) + q.push(i); + while (!q.empty()) + { + int man = q.front(); + q.pop(); + for (int woman : menPref[man]) + { + if (womanMatch[woman] == -1) + { + womanMatch[woman] = man; + manMatch[man] = woman; + break; + } + else + { + int otherMan = womanMatch[woman]; + if (mapWM[woman][otherMan] > mapWM[woman][man]) + { + manMatch[otherMan] = -1; + q.push(otherMan); + womanMatch[woman] = man; + manMatch[man] = woman; + break; + } + } + } + } + + return manMatch; +} + +int main() { + IOS; + int t; + cin>>t; + while(t--) { + int n,temp; + cin>>n; + vector> menPref(n), womenPref(n); + for (int i = 0; i < n; ++i) { + womenPref[i].resize(n); + cin>>temp; + for (int j = 0; j < n; ++j) { + cin>>womenPref[i][j]; + womenPref[i][j]--; + } + } + for (int i = 0; i < n; ++i) { + menPref[i].resize(n); + cin>>temp; + for (int j = 0; j < n; ++j) { + cin>>menPref[i][j]; + menPref[i][j]--; + } + } + vector marriages = stableMariage(menPref,womenPref); + for (int i = 0; i < n; ++i) { + cout< Date: Tue, 24 Dec 2019 11:33:28 +0530 Subject: [PATCH 2/2] #211 solved Program for nth fibonnaci number and catalan number --- catalan.cpp | 24 ++++++++++++++++++++++++ fib.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 catalan.cpp create mode 100644 fib.cpp diff --git a/catalan.cpp b/catalan.cpp new file mode 100644 index 0000000..87a5345 --- /dev/null +++ b/catalan.cpp @@ -0,0 +1,24 @@ +#include +#define ull unsigned long long int + +using namespace std; + +//Program to find the nth catalan number + +ull catalan(ull n) { + ull c = 1; + for (int i = 0; i < n; ++i) { + c *= (2*n-i); + c /= (i+1); + } + c /= (n+1); + return c; +} + +int main() { + ull n; + cin>>n; + cout< +#define ull unsigned long long int + +using namespace std; + +//Program to find the nth fibonnaci number + +int main() { + ull n; + cin>>n; + ull t1,t2; + t1 = 1; + t2 = 1; + if(n==1 || n==2) { + cout<<1<