-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Manav Aggarwal
authored and
Manav Aggarwal
committed
Apr 4, 2017
0 parents
commit 8a429aa
Showing
477 changed files
with
24,130 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* Written By Manav Aggarwal */ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define endl '\n' | ||
#define ll long long | ||
|
||
ll gcd(ll a, ll b) | ||
{ | ||
if(b == 0) | ||
{ | ||
return a; | ||
} | ||
else | ||
{ | ||
return gcd(b, a%b); | ||
} | ||
} | ||
ll lcm(ll a, ll b){return (a*b)/gcd(a,b);} | ||
int main() { | ||
|
||
ll t; | ||
cin >> t; | ||
while(t--) | ||
{ | ||
ll s, e1, e2, v1, v2, cmn = 0, lcmv; | ||
cin >> s >> e1 >> e2 >> v1 >> v2; | ||
e1 -= s; e2 -= s; | ||
if(v1 > 0 && v2 < 0 || (v1 < 0 && v2 > 0)) | ||
{ | ||
cout << 1 << endl; | ||
continue; | ||
} | ||
e1 = abs(e1); e2 = abs(e2); | ||
v1 = abs(v1); v2 = abs(v2); | ||
lcmv = lcm(v1, v2); | ||
cmn = (min(e1, e2))/ lcmv; | ||
cout << cmn + 1 << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* Written By Manav Aggarwal */ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define endl '\n' | ||
#define ll long long | ||
#define MAX 300010 | ||
ll MOD = 1e9 + 7; | ||
struct node | ||
{ | ||
mutable bool left, right; | ||
ll key; | ||
mutable ll position, index; | ||
bool operator < (node other) const | ||
{ | ||
return key < other.key; | ||
} | ||
}; | ||
|
||
set<node> vals; | ||
ll arr[MAX]; | ||
void insrt(node k) | ||
{ | ||
ll num; | ||
if(k.index == 0) | ||
{ | ||
k.position = 1; | ||
num = 1; | ||
vals.insert(k); | ||
} | ||
else | ||
{ | ||
vals.insert(k); | ||
auto it = vals.find(k); | ||
auto it1 = it; it1++; | ||
if(it == vals.begin()) | ||
{ | ||
it++; | ||
if(!(it -> left)) | ||
{ | ||
it -> left = true; | ||
num = ((it -> position)*2); | ||
num %= MOD; | ||
--it; | ||
it -> position = num; | ||
} | ||
} | ||
else if(it1 == vals.end()) | ||
{ | ||
it1--; it1--; | ||
if(!(it1->right)) | ||
{ | ||
it1 -> right = true; | ||
num = (it1 -> position)*2 + 1; | ||
num %= MOD; | ||
++it1; | ||
it1 -> position = num; | ||
} | ||
} | ||
else | ||
{ | ||
it--; | ||
if(!(it -> right)) | ||
{ | ||
it -> right = true; | ||
num = (it -> position)*2 + 1; | ||
num %= MOD; | ||
++it; | ||
it -> position = num; | ||
} | ||
else if(!(it1 -> left)) | ||
{ | ||
it1 -> left = true; | ||
num = (it1 -> position)*2; | ||
num %= MOD; | ||
--it1; | ||
it1 -> position = num; | ||
} | ||
} | ||
} | ||
arr[k.index] = num % MOD; | ||
} | ||
int main() | ||
{ | ||
ios_base::sync_with_stdio(0); cin.tie(0); | ||
ll n, i, num; | ||
cin >> n; | ||
for(i = 0; i < n; i++) | ||
{ | ||
node k; | ||
cin >> k.key; | ||
k.left = k.right = false; | ||
k.index = i; | ||
insrt(k); | ||
num = arr[i] % MOD; | ||
cout << num << " "; | ||
} | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <iostream> | ||
using namespace std; | ||
int add(int x, int y); | ||
int main() | ||
{ | ||
int input1,input2,answer; | ||
cin >> input1 >> input2; | ||
answer = add(input1, input2); | ||
cout << answer; | ||
return 0; | ||
} | ||
int add(int x, int y) | ||
{ | ||
int carry; | ||
while (y!=0) | ||
{ | ||
carry = x & y; | ||
x = x^y; | ||
y = carry << 1; | ||
} | ||
return x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Written By Manav Aggarwal */ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define endl '\n' | ||
#define ll long long | ||
|
||
string add_zeros(string str, ll n) | ||
{ | ||
while(n--) | ||
{ | ||
str += '0'; | ||
} | ||
return str; | ||
} | ||
string add(string num1, string num2) | ||
{ | ||
string sum = "", a, b; | ||
ll i, summer, carry = 0; | ||
a = string(num1.rbegin(), num1.rend()); | ||
b = string(num2.rbegin(), num2.rend()); | ||
if(a.length() > b.length()) | ||
{ | ||
b = add_zeros(b, a.length()-b.length()); | ||
} | ||
else | ||
{ | ||
a = add_zeros(a, b.length() - a.length()); | ||
} | ||
for(i = 0; i < min(a.length(), b.length()); i++) | ||
{ | ||
summer = (ll)(a[i] + b[i] - 2*(ll)('0') + carry); | ||
carry = 0; | ||
if(summer > 9) | ||
{ | ||
carry = summer/10; | ||
summer%= 10; | ||
} | ||
sum += (char)(summer + '0'); | ||
} | ||
if(carry!=0) | ||
{ | ||
sum += (char)(carry + '0'); | ||
} | ||
return string(sum.rbegin(), sum.rend()); | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); cin.tie(0); | ||
cout << add("42000", "1"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define endl '\n' | ||
void BFS(vector <int> edges[], v) | ||
{ | ||
set <int> visited; | ||
queue <int> q; | ||
q.push(v); | ||
visited.insert(v); | ||
while(q.size() != 0) | ||
{ | ||
v = q.front(); | ||
q.pop(); | ||
for(int i = 0; i < edges[v].size(); i++) | ||
{ | ||
if(visited.count(edges[v][i]) == 0) | ||
{ | ||
q.push(edges[v][i]); | ||
visited.push(edges[v][i]); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define endl '\n' | ||
|
||
int min(int a, int b); | ||
|
||
// Returns value of Binomial Coefficient C(n, k) | ||
int binomialCoeff(int n, int k) | ||
{ | ||
int C[n+1][k+1]; | ||
int i, j; | ||
|
||
// Caculate value of Binomial Coefficient in bottom up manner | ||
for (i = 0; i <= n; i++) | ||
{ | ||
for (j = 0; j <= min(i, k); j++) | ||
{ | ||
// Base Cases | ||
if (j == 0 || j == i) | ||
C[i][j] = 1; | ||
|
||
// Calculate value using previosly stored values | ||
else | ||
C[i][j] = C[i-1][j-1] + C[i-1][j]; | ||
} | ||
} | ||
|
||
return C[n][k]; | ||
} | ||
|
||
// A utility function to return minimum of two integers | ||
int min(int a, int b) | ||
{ | ||
return (a<b)? a: b; | ||
} | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(0); | ||
int n, k; | ||
cin >> n >> k; | ||
cout << binomialCoeff(n, k); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* Written By Manav Aggarwal */ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define endl '\n' | ||
#define ll long long | ||
|
||
ll binomialCoeff(ll n, ll k) | ||
{ | ||
ll ans = 1, i; | ||
if(k > n - k) | ||
{ | ||
k = n-k; | ||
} | ||
|
||
for(i = 0; i < k; i++) | ||
{ | ||
ans *= (n - i); | ||
ans /= (i+1); | ||
} | ||
return ans; | ||
} | ||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); cin.tie(0); | ||
cout << binomialCoeff(5, 3); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* Written By Manav Aggarwal */ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define endl '\n' | ||
#define ll long long | ||
#define mp make_pair | ||
#define pci pair<char, ll> | ||
bool isValid(pci p) | ||
{ | ||
if(p.first >= 'a' && p.first <= 'h' && p.second >= 1 && p.second <= 8) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); cin.tie(0); | ||
char a; | ||
ll b; | ||
cin >> a >> b; | ||
map<pci, bool> visited; | ||
map<pci, pci > came_from; | ||
queue<pci > frontier; | ||
frontier.push(mp('a', 1)); | ||
pci curr; | ||
while(!frontier.empty()) | ||
{ | ||
curr = frontier.front(); | ||
frontier.pop(); | ||
visited[curr] = true; | ||
if(curr.first == a && curr.second == b) | ||
{ | ||
break; | ||
} | ||
pci h2fv1l = mp((char)(curr.first - 1), curr.second + 2), h2fv1r = mp((char)(curr.first + 1), curr.second + 2), h2bv1l = mp((char)(curr.first - 1), curr.second - 2); | ||
pci h2bv1r = mp((char)(curr.first + 1), curr.second - 2), h1fv2l = mp((char)(curr.first - 2), curr.second + 1), h1fv2r = mp((char)(curr.first + 2), curr.second + 1); | ||
pci h1bv2l = mp((char)(curr.first - 2), curr.second - 1), h1bv2r = mp((char)(curr.first + 2), curr.second - 1); | ||
vector<pci > pairs; | ||
pairs.push_back(h2fv1l), pairs.push_back(h2fv1r), pairs.push_back(h2bv1l), pairs.push_back(h2bv1r), pairs.push_back(h1fv2l), pairs.push_back(h1fv2r), pairs.push_back(h1bv2l), pairs.push_back(h1bv2r); | ||
for(ll i = 0; i < pairs.size(); i++) | ||
{ | ||
if((!visited[pairs[i]]) && isValid(pairs[i])) | ||
{ | ||
came_from[pairs[i]] = curr; | ||
frontier.push(pairs[i]); | ||
visited[pairs[i]] = true; | ||
} | ||
} | ||
} | ||
vector<pci > path; | ||
while(!(curr.first == 'a' && curr.second == 1)) | ||
{ | ||
path.push_back(curr); | ||
curr = came_from[curr]; | ||
} | ||
for(ll i = path.size()-1; i >= 0; i--) | ||
{ | ||
cout << path[i].first << path[i].second << " "; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.