Skip to content

Commit 7e294fe

Browse files
committed
sublime snippets
1 parent 5efcfe0 commit 7e294fe

30 files changed

+1086
-0
lines changed

Diff for: sublime/AutoPep8.sublime-settings

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"format_on_save": true
3+
}

Diff for: sublime/Default (Windows).sublime-keymap

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{ "keys": ["ctrl+keypad_divide"], "command": "toggle_comment", "args": { "block": false } },
3+
{ "keys": ["ctrl+shift+keypad_divide"], "command": "toggle_comment", "args": { "block": true } },
4+
{ "keys": ["ctrl+shift+z"], "command": "cancel_build" }
5+
6+
]

Diff for: sublime/Euclid_Extended.sublime-snippet

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<snippet>
2+
<content><![CDATA[
3+
/*
4+
Diophantine eq >
5+
ax+by=c will have intergral soln if gcd(a , b) is divisible by c . {a,b,c,x,y} are integers
6+
7+
Extended gcd
8+
9+
if
10+
ax+by = gcd(a , b) then we can find x and y
11+
ax+by = gcd(a , b) = gcd(b , a%b) = b(x1) + (a%b)(y1) = b(x1) + (a - b*floor(a/b))(y1)
12+
13+
x = y1
14+
y = x1 - (floor(a/b)*y1)
15+
16+
if(b==0)
17+
return {a , 1, 0}; // {gcd , x1, y1}
18+
19+
a>=b
20+
*/
21+
22+
vector<int>ExtendedEuclid(int a , int b)
23+
{
24+
25+
26+
if (b == 0)
27+
return {a , 1 , 0};
28+
29+
vector<int> small = ExtendedEuclid(b, a % b);
30+
31+
return {small[0] , small[2] , small[1] - (a / b) *small[2]}; // gcd , x1 , y1
32+
}
33+
/*
34+
vector<int> res = ExtendedEuclid(a , b);
35+
debug(res);
36+
*/
37+
]]></content>
38+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
39+
<tabTrigger>Euclid_Extended</tabTrigger>
40+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
41+
<!-- <scope>source.python</scope> -->
42+
</snippet>

Diff for: sublime/FastOlympicCoding.sublime-settings

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
3+
}

Diff for: sublime/MMInverse.sublime-snippet

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<snippet>
2+
<content><![CDATA[
3+
/*
4+
multiplicative modulo inverse
5+
(a*b)mod m =1 ;
6+
find b ? a,b,m are integer
7+
8+
a*b + m*Q = 1 ;
9+
hence soln (b) exists iif a and m are coprime;
10+
final eq = a*b + m*Q = gcd(a,m) // Extended Euclid with b and Q(it is some multiple) as soln of eq
11+
*/
12+
13+
vector<int>ExtendedEuclid(int a , int b)
14+
{
15+
if (b == 0)
16+
return {a , 1 , 0};
17+
18+
vector<int> small = ExtendedEuclid(b, a % b);
19+
20+
return {small[0] , small[2] , small[1] - (a / b) *small[2]}; // gcd , x1 , y1
21+
}
22+
int MMInverse(int a , int m)
23+
{
24+
if(__gcd(a,m)!=1) // not coprime ,,, if m is prime , use fermat little thrm
25+
return -1;
26+
vector<int> res = ExtendedEuclid(a , m);
27+
return (res[1] + m ) % m; // in case res1 is neg
28+
}
29+
]]></content>
30+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
31+
<tabTrigger>MMInverse</tabTrigger>
32+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
33+
<!-- <scope>source.python</scope> -->
34+
</snippet>

Diff for: sublime/Package Control.sublime-settings

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"bootstrapped": true,
3+
"in_process_packages":
4+
[
5+
],
6+
"installed_packages":
7+
[
8+
"10% Too Dull for My Tastes Color Scheme",
9+
"AutoPEP8",
10+
"CppFastOlympicCoding",
11+
"EasyClangComplete",
12+
"Package Control",
13+
"SublimeAStyleFormatter",
14+
],
15+
}

Diff for: sublime/Package Control.user-ca-bundle

Whitespace-only changes.

Diff for: sublime/Preferences.sublime-settings

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"theme": "Adaptive.sublime-theme",
3+
"ignored_packages":
4+
[
5+
"Vintage",
6+
],
7+
"color_scheme": "auto",
8+
"dark_color_scheme": "Monokai.sublime-color-scheme",
9+
"light_color_scheme": "Packages/10% Too Dull for My Tastes Color Scheme/scotchy.tmTheme",
10+
"font_size": 10,
11+
}

Diff for: sublime/address.sublime-snippet

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<snippet>
2+
<content><![CDATA[
3+
C:\Users\dangi\AppData\Roaming\Sublime Text\Packages\User
4+
]]></content>
5+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
6+
<tabTrigger>address</tabTrigger>
7+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
8+
<!-- <scope>source.python</scope> -->
9+
</snippet>

Diff for: sublime/articulation points.sublime-snippet

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<snippet>
2+
<content><![CDATA[
3+
/*
4+
case 1 : if root -> is an articluation point , if it has 2 or more subtrees/ childrens
5+
6+
case 2 : if not root -> looking through the edges starting from vertex v≠root.
7+
If the current edge (v,child) is such that none of the vertices child or its descendants
8+
in the DFS traversal tree has a back-edge to any of ancestors of v,
9+
then v is an articulation point. Otherwise, v is not an articulation point.
10+
11+
*/
12+
const int N = 100001;
13+
vector<int>graph[N];
14+
vector<bool>visited(N, false);
15+
vector<int> intime(N, -1) , low(N, -1);
16+
int timer = 0 ;
17+
18+
19+
void dfs(int sv, int parent)
20+
{
21+
visited[sv] = 1;
22+
intime[sv] = low[sv] = timer;
23+
timer++ ;
24+
25+
int children = 0;
26+
for (int child : graph[sv])
27+
{
28+
if (child == parent)continue;
29+
30+
if (visited[child]) // this child is the ancestor of sv , is a backedge
31+
{
32+
low[sv] = min(low[sv] , intime[child]);
33+
}
34+
else // this child is the descendent ,is a forward edge
35+
{
36+
dfs(child, sv);
37+
38+
low[sv] = min(low[sv] , low[child]); // if child has an ancestor , sv also has same ancestor
39+
40+
if (low[child] >= intime[sv] and parent != -1)
41+
is_cutvertex(sv); // todo
42+
43+
++children;
44+
}
45+
}
46+
if (parent == -1 and children > 1)
47+
is_cutvertex(sv);
48+
}
49+
50+
51+
]]></content>
52+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
53+
<tabTrigger>cutvertex</tabTrigger>
54+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
55+
<!-- <scope>source.python</scope> -->
56+
</snippet>

Diff for: sublime/binomialcoff.sublime-snippet

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<snippet>
2+
<content><![CDATA[
3+
const int mod = 1000000000 + 7;
4+
int add(int a, int b)
5+
{
6+
int ans = ((a % mod) + (b % mod)) % mod;
7+
return ans;
8+
}
9+
10+
int binomialCoeff(int n, int k)
11+
{
12+
int C[n + 1][k + 1];
13+
int i, j;
14+
15+
// Caculate value of Binomial Coefficient
16+
// in bottom up manner
17+
for (i = 0; i <= n; i++) {
18+
for (j = 0; j <= min(i, k); j++) {
19+
// Base Cases
20+
if (j == 0 || j == i)
21+
C[i][j] = 1;
22+
23+
// Calculate value using previously
24+
// stored values
25+
else
26+
C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
27+
}
28+
}
29+
30+
return C[n][k];
31+
}
32+
]]></content>
33+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
34+
<tabTrigger>binomialCoeff</tabTrigger>
35+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
36+
<!-- <scope>source.python</scope> -->
37+
</snippet>

Diff for: sublime/binomialfast.sublime-snippet

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<snippet>
2+
<content><![CDATA[
3+
4+
const int N = 1000001;// NCR
5+
const int mod =1e9+7;
6+
ll factorialNumInverse[N + 1];
7+
ll naturalNumInverse[N + 1];
8+
ll fact[N + 1];
9+
void InverseofNumber()
10+
{ ll p=mod;
11+
naturalNumInverse[0] = naturalNumInverse[1] = 1;
12+
for (int i = 2; i <= N; i++)
13+
naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
14+
}
15+
void InverseofFactorial()
16+
{ ll p=mod;
17+
factorialNumInverse[0] = factorialNumInverse[1] = 1;
18+
for (int i = 2; i <= N; i++)
19+
factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
20+
}
21+
void factorial()
22+
{ ll p=mod;
23+
fact[0] = 1;
24+
for (int i = 1; i <= N; i++) {
25+
fact[i] = (fact[i - 1] * i) % p;
26+
}
27+
}
28+
ll Binomial(ll N, ll R)
29+
{ ll p=mod;
30+
ll ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R])% p;
31+
return ans;
32+
}
33+
void precompute()
34+
{
35+
InverseofNumber();
36+
InverseofFactorial();
37+
factorial();
38+
//cout << Binomial(N, R) << endl;
39+
}
40+
41+
]]></content>
42+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
43+
<tabTrigger>binomialfast</tabTrigger>
44+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
45+
<!-- <scope>source.python</scope> -->
46+
</snippet>

Diff for: sublime/bridges-graph.sublime-snippet

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<snippet>
2+
<content><![CDATA[
3+
/*
4+
so the idea is :
5+
6+
Let's say we are in the DFS, looking through the edges starting from vertex v.
7+
The current edge (sv,child) is a bridge if and only if none of the vertices child and its
8+
descendants in the DFS traversal tree has a back-edge to vertex sv or any of its ancestors.
9+
Indeed, this condition means that there is no other way from sv to child except for edge (sv,child)
10+
11+
backedge can never be a bridge.
12+
13+
we maintain a low array which basically maintains the lowest time / minimum time , this time is
14+
either the low time of node , or child , or intime of ancestor if it has . low array would contain
15+
intime of the node , or of the ancestor (in case if it has )
16+
17+
for a backedge : low time of node would be intime of its ancestor other than parent ,
18+
as intime of ancestor is less than the node , which means edge ancestor and
19+
node is not a bridge.
20+
21+
for a forward edge : it is a bridge, if child wont have any backedge , hence if low time of child would
22+
be equal to its intime , which would be greater than the intime of the node itself,
23+
which makes an edge a bridge .
24+
25+
26+
so code looks like :
27+
*/
28+
29+
const int N = 100001;
30+
vector<int>graph[N];
31+
vector<bool>visited(N, false);
32+
vector<int> intime(N, -1) , low(N, -1);
33+
int timer = 0 ;
34+
35+
36+
void dfs(int sv, int parent)
37+
{
38+
visited[sv] = 1;
39+
intime[sv] = low[sv] = timer;
40+
timer++ ;
41+
42+
for (int child : graph[sv])
43+
{
44+
if (child == parent)continue;
45+
46+
if (visited[child]) // this child is the ancestor of sv , is a backedge
47+
{
48+
low[sv] = min(low[sv] , intime[child]);
49+
}
50+
else // this child is the descendent ,is a forward edge
51+
{
52+
dfs(child, sv);
53+
// now we check relation between sv and its this child
54+
55+
if (low[child] > intime[sv]) // currently ig intime[sv]=low[sv]
56+
is_bridge(sv, child); // todo
57+
58+
low[sv] = min(low[sv] , low[child]); // if child has an ancestor , sv also has same ancestor
59+
}
60+
}
61+
}
62+
63+
64+
]]></content>
65+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
66+
<tabTrigger>bridges-graph</tabTrigger>
67+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
68+
<!-- <scope>source.python</scope> -->
69+
</snippet>

Diff for: sublime/debug.sublime-snippet

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<snippet>
2+
<content><![CDATA[
3+
https://codeforces.com/blog/entry/68809#:~:text=To%20debug%2C%20just%20type%3A%20debug,requires%20C%2B%2B%2011%20or%20above.&text=Primitive%20data%20types%3A%20bool%20%2C%20int,%3A%3Apair%20%2C%20std%3A%3Astring
4+
]]></content>
5+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
6+
<tabTrigger>tourist</tabTrigger>
7+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
8+
<!-- <scope>source.python</scope> -->
9+
</snippet>

Diff for: sublime/direction_graph.sublime-snippet

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<snippet>
2+
<content><![CDATA[
3+
int dirn[8][2] = {{-1, 0} , {-1, -1}, { -1, 1}, {0, -1}, {0, 1 } , {1, -1}, {1, 0 }, {1, 1 }};
4+
int dirn[8][2] = {{ 2, 1} , { 2, -1} ,{ -2 ,1} ,{-2,-1}, {1 ,-2} , {1 , 2}, {-1, 2}, {-1,-2}};
5+
int dirn[4][2] = {{1 , 0} , {-1 ,0} , {0 ,-1} , {0 , 1}};
6+
7+
bool valid(int x , int y, int n , int m)
8+
{
9+
return x >= 0 and y >= 0 and x < n and y < m;
10+
}
11+
12+
13+
]]></content>
14+
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
15+
<tabTrigger>direction_graph</tabTrigger>
16+
<!-- Optional: Set a scope to limit where the snippet will trigger -->
17+
<!-- <scope>source.python</scope> -->
18+
</snippet>

0 commit comments

Comments
 (0)