Friday, 18 July 2014

A checklist for every Computer Science student


The below List contains essential things according to me a
computer science student should know. Please add your views in comments.


Email:
Access e-mail system using username and password
Change username-password.
Receive / read an e-mail message
Reply to an e-mail message
Compose and send an original e-mail message
Attach a file to an e-mail message
Meaning of cc, bcc etc.

To create a letter or essay, which software program would be the best choice to use?
Other than CAPS LOCK, which key can you use to insert uppercase/capital letters in a
document?
Tell about these things
Firefox, chrome, power point, excel, ms word etc.
how to check whether an e-mail address is valid or not?
valid email address.
concept of ip address.
concept of LAN.
name some good search engines. Use of search engines etc.

create a directory, edit files, search files, 
Use of ls, pwd, rm, mv, cp command.
How to rename a file using mv command?
How to delete a directory.
How to open application through command line?
How to open two programs simultaneously from your terminal?
Concept of chmod, permissions, installing softwares, installing linux on your computer.

How to print your files on cse ground labs?
Learn use of ppr command.

image editor?

how to create presentations in linux or windows?

how can you select multiple files from a list of files ?

how to permanently delete the files?

keyboard shortcuts for cut, copy, paste, changing the tabs, cut/copy/paste from
terminal, open terminal, close terminal, saving a file, save as, delete a file,
help, closing a program,
for capitalizing a letter, for opening a new tab in browser, closing a tab in
browser, refreshing the webpage, changing the current tab to another tab in browser.

undo, redo, bold, italic etc.

click, double click, right click, scrolling etc.

concept of bits, byte, RAM, ROM, hard disk. What is inside the CPU?

dragging a file

what is an operating system? names of famous operating systems?

meaning of www, ip, netmask, LAN etc.

wikipedia.
search an article.
create your account.
edit article.

know about stackoverflow, mathoverflow, stackexchange,  etc. sites?

know about programming competitions like ACM-ICPC, visit spoj, topcoder.com,
codechef, codeforces etc.

know about top online courses of the universities around the world eg. nptel,
coursera, OCW

search a paper on google scholar.

search for graph making softwares on web. (hint: you can use google too)

create online netbanking and learn how to do online transcations.
how to online order books or any other goods online?

how to use google drive, google doc, creating google forms, 

how to create blog ? Famous sites for creating your blog?

how to create a profile on social networking sites like facebook, G+, quora, twitter?

how to maintain your home page?

google search: 
how to search on a specific site?
how to use it as a calculator?
how to search for a specific file?
how to search exact phrases?

know about DC++

how to change proxy in your browser?

increase your typing speed, search for good typing speed increasing softwares.

how to change passwords of your computers?

concept of root user on linux?, sudo etc.

concept of ssh and scp.

creating bookmarks.

how to write README files?

Thursday, 20 March 2014

Strtok Function in C

    string s;
    getline(cin,s);
    char *pch;
    char str[10000];
    // you s.c_str() returns a const char * pointer you can not directly cast to char *, Hence char * str=s.c_str() will give you compilation error, Hence allocate the memory for str first and then use strcpy function to copy the constant string into the memory.
    strcpy(str,s.c_str());
 
    pch=strtok(str,"-");
    // gives you the first token, if it is NULL, all the characters in the string were from delimeters.
    while(pch!=NULL)
    {
        printf("HI%sHI\n",pch);
        // in the subsequent calls, always pass NULL.
        pch=strtok(NULL,"-");
    }
 
    // note that str is getting changed by the the strtok function.

You can also do the same thing in this way too.
vector split(string s, string del = " ") { char *word, *buf, *delim; vector res; delim = strdup(del.c_str()); buf = strdup(s.c_str()); for (word = strtok(buf, delim); word; word = strtok(0, delim)) res.push_back(string(word)); free(buf); free(delim); return res; }

strdup can also be used instead of strcpy, but you should never forget to free the memory, though most of time not necessary in contests.

Refereneces 
http://www.cplusplus.com/reference/cstring/strtok/
http://apps.topcoder.com/forums/?module=Thread&threadID=672251&start=0

Wednesday, 26 February 2014

Invitation for participation in IOPC 2014, IIT Kanpur

The Department of Computer Science & Engineering, Indian Institute of Technology, Kanpur (http://cse.iitk.ac.in/) and the Techkriti team](http://techkriti.org/) presents the 2014 edition of IOPC, the annual International Online Programming Contest of IIT Kanpur. This 24 hour long contest will have you competing with some of the best coders in the world in solving problems of an algorithmic nature.

IOPC 2014 will be held from 1200 hrs on March 1st to 1200 hrs on March 2nd (IST) http://www.timeanddate.com/worldclock/fixedtime.html?msg=IOPC+2014&iso=20140301T12&p1=539&ah=23&am=59. Teams of upto 3 members can participate in the contest. To be eligible for prizes, the teams need to be comprised of students who are currently registered in some university only.

IOPC 2014 will be hosted on Directi's Codechef platform .Please register on the contest page(http://www.codechef.com/IOPC2014) . Teams need to register on the [IOPC](tiny.cc/iopc2014) site as well to be eligible for prizes.

Visit the Codechef contest page(http://www.codechef.com/IOPC2014) and the IOPC site (http://tiny.cc/iopc2014) for rules and more details.
Join us on our FB event page (https://www.facebook.com/events/696412627048318/) for more updates.

You can view last years problems at codechef.
http://www.codechef.com/IOPC2011
http://www.codechef.com/IOPC2012
http://www.codechef.com/IOPC2013

See you in the contest !!!!

Sunday, 2 February 2014

WPC # 4 Editorials







First of all I want to say you sorry for not making some really easy problems. Next time I will make sure that this does not happen :) First time experimenting latex in editorials, Hope you will like it :)


Editorials:
Gopu and Frogs:
     If you have not come across permanent problem, Then look at  http://en.wikipedia.org/wiki/Permanent. As might you read permanent can used to find number of perfect matchings in a graph. Now you have to find perfect matchings in this case too, but in this case, you select an edge by some probability. So you just add this constraints to the problem.
   For finding number of perfect matchings in a graph, you can use a dp with bitmask in O($2^n n$).
   See the code of http://www.codechef.com/viewplaintext/460759 of uwi. go to permanent section.
   Problems to solve: http://www.codechef.com//problems/IOPC1114. You can also see its explanation by Raziman TV on http://razimantv.files.wordpress.com/2011/02/booklet1.pdf.
  
Arrangement Validity:
  From the earlier arrangement validity problem in the first part, you might have known the condition of when the answer is not possible. Go solve the problem for more clarity http://www.spoj.com/problems/SPCU/.
  Now how to build a correct order. (Exercise) You can prove that if answer exists then it is unique. Go from right to left, Suppose what is the height of last person you can have is smallest positive integer which is not equal to a[n - 1]. eg in case of last person having a[i] = 2, You can have height = 1. in case of 1, you can have 2.
   So on generalizing this, you are on the $i^{th}$ from back and you want to know its height, You have to answer queries like this. Find smallest positive integer which is not equal to any of the values from a[i + 1] to a[n - 1]. You can use segment tree or BIT for this kind of queries.
   Try solving http://www.spoj.com/problems/ORDERSET/ for getting more insight into the solution.

Maggu and Weird Things.
 This problem is really lovely problem. You can use matrix exponentiation to solve this problem. Hints of constraints being n $\leq$ 50 and m  $ \leq 10^9$.
  Basically each transformation can be characterized by a matrix multiplication. For doing the first operation, you can create matrix really easily. First try creating matrix for only operation 1, Take simple test cases, You will notice the pattern very fast.
 See the marix for only operation 1, Assume n = 4, k = 2
$ \\[ \\left( \\begin{array}{ccc}
1 & -1 & 0 & 0 \\\\
0 & 1 & -1 & 0\\\\
0 & 0 & 1 & -1 \\\\
-1 & 0 & 0 & 1\\\\
\\end{array} \\right)\\] $
Did you guys notice the pattern, if yes, then formalize the intuition.


Now let us see the case of swapping the $i^{th}$ and $(i+1)^{th}$ element.
For this you can swap two consecutive rows of matrix obtained in the first step.
ie.
$ \[ \left( \begin{array}{ccc}
0 & 1 & -1 & 0\\ 
1 & -1 & 0 & 0 \\
-1 & 0 & 0 & 1\\ 
0 & 0 & 1 & -1 \\
\end{array} \right)\] $

Now you have got your matrix, Exponentiate it n times ($\mathbb{O}$ ($n^3$ log m) and enjoy yourselves :)

Maggu and Magguness Level:
  This problem is so cute to solve. Believe me if you have not solved upto now, first solve yourself.
First let us detect when answer will be -1, When there exists cycles in the graph, You will get contradictions and hence will be -1. eg 1-> 2 and 2 -> 3 and 3 -> 1 is not possible.
  Now for first find the vertices which are connected to the vertex id in the graph. Also find the number of vertices which are connected to it in the reverse graph. Call the first number A and second number B. Then the answer to the problem should be all the number from B to N - A + 1.
 Take examples and try solving the problem.

Petya and Repairment of Roads.
  This problem is really famous. See http://www.cc.gatech.edu/fac/Vijay.Vazirani/book.pdf.
This book is really a gem book. See its exercise 3.2, Our problem is similar to this. Now use the hint provided in book and solve the problem.
 
Also solve http://www.codechef.com/problems/RHOUSE.

Maggu and Mystery:
   In simplified language problem is to find min no of operations needed to do on a array to get atleast d distinct elements. In a single operations you can increase or decrease the $i^{th}$ element by atmost $v_i$.
Solution is to use min-cost max flow. Note that it wont make any sense to convert a number into less than -250 (As n $\leq$ 50 and $v_i$ $\leq$ 5) and greater than 1250. So a make a graph of n nodes on one side and 1250 + 250 nodes on the other sides. For each edge add the capacity of 1 and cost equal to $ceil (abs (a_i - j), v_i$. You need to add two special vertices, start and target vertices. Connect first n vertices to start vertex using 1 cap and 0 cost. and similarly connect the target vertex to all the $j^{th}$ vertices (ie vertices on the second part).

Maggu and Vectors : (Wrriten by Abhilash Kumar)
In this problem we have to check that do 3 vectors a,b,c exists such that :
    abc=0
Because we have assumed vectors to as non-directional like a simple line segment which can be shifted along x and y axes but its orientation cannot be altered.
It can be easily noticed that solution to above equation exists if solution for one of these equation exists:
    a+b=c
    b+c=a
    c+a=b
As the x and y components lie between -1000 and 1000 we can simply precompute sum of each pair of vectors and store in  an 2-D array of bool of size 4000*4000 which denotes that is sum of two vectors equals to that index exists or not(as we can not have negative indexes we can simply shift origin by 2000 to take care of it). And later check for each vector that do we have a sum of which equals  of this vector.If any vector satisfy this then we have a solution else no.
Complexity = $\mathbb{O} ( 4000*4000 + n^2 + n )$
 Note: Many wrong answer occurred because people were also counting non-degenerate triangle.
To avoid this problem we just had to add only non-zero vectors that were non-parallel .
Maggu and Triangles : (Written by Abhilash Kumar)
We have to find number of non-congruent triangles with perimeter N.
The answer to this question is Alcuin's sequence Nth element of this sequence is coefficient of $x^n$ in $x^3/((1-x^2)*(1-x^3)*(1-x^4))$.
After solving the above sequence (as done here) we get :
    $T_n = < (n+3)^2 / 48 > $ when n is odd.
              = $ < n^2 / 48> $ if n is even.
where $ < > $ denotes the nearest integer to x . Note that here x will never be exactly between two integers.







A Cross Product Formula

\[\mathbf{V}_1 \times \mathbf{V}_2 =  \begin{vmatrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
\frac{\partial X}{\partial u} &  \frac{\partial Y}{\partial u} & 0 \\
\frac{\partial X}{\partial v} &  \frac{\partial Y}{\partial v} & 0
\end{vmatrix}  \]
 




Wednesday, 15 January 2014

Multiplication of two long numbers modulo a long number.

LL multiplication (LL a, LL b, LL mod) {
    LL res = (a * ((long double) b / (long double) mod));
    // put the number in long double, and then reduce the value to LL, forget 
    overflow.
    res = a * b - res * mod;
    if (res >= mod) res -= mod;
    if (res < 0) res += mod;
    return res;
}

Tuesday, 14 January 2014

WCP #3 And Editorials

WPC #3 was held on this sunday. http://aca.cse.iitk.ac.in/public/
Problems have been moved to spoj.

Editorials: (these editorials are merely hints, You need to work things yourself for final answers)
Hope you will like them. Leave a comment if something is unclear or needs to be modified, Also leave your opinion about the contest.

1. Gopu and Palindromes: (http://www.spoj.com/problems/SPCS/)
     Consider the string s. Let it has some consecutive characters of length L, Then you can directly replace L by just 1 character. After such replacements just check if the string is palindrome or not?
     eg. s = "ababbbaaa".
           s = "ababa". Replace bbb with b and aaa with a.
     You need to do this in O(n).

2.Gopu and Validity of Arrangement: (http://www.spoj.com/problems/SPCU/)
   You can easily prove that if answer exists then it is unique, Only condition you need to check that any ith indexed person does not say that $\ge$ i persons are before him. You can relate this problem with permutations.

3. Gopu and Digits Divisibility: (http://www.spoj.com/problems/SPCU/)
   You can easily do a brute force. Think about it why this works, Hint: for checking divisibility by 9, sum of digits should be divisible by 9. (Though hint is not of great use in the proof).

4. Gopu and Function: (http://www.spoj.com/problems/SPCM/)
    Value of n will be atleast halved in each computation of f. As Take the best cases when n = 2*p where p is prime, Sum of divisors is 2 + p which is 2 + n / 2. In other cases, sum would be even less than n/2. For finding prime divisors of n, use simple sqrt algorithm. Final complexity would be O($\sqrt[2]{n}$ logn).

5. Gopu and Create Collections Part two (http://www.spoj.com/problems/SPCJ/)
   You can use dp over the tree for solving this. You can use a greedy algo also. Sort the numbers in increasing order, go from right to left and for each number K if you find a number K/2 which is not yet taken then take it and add it to answer.
   You can also use greedy algorithm by constructing the binary tree explicitly and then going from leaves to the root of the tree.

6. Gopu and Combinatorics on Graphs: (http://www.spoj.com/problems/SPCE/)
  This is standard problem. You should know http://en.wikipedia.org/wiki/Cayley%27s_formula. Then figuring out things wont be tough. I dont want to give formulla as I want you to work it out.

7. Gopu and Counting bitwise prime numbers: (http://www.spoj.com/problems/SPCO/)
   This problem had one slow solution:
     use dp(i, tight): where i denotes the position in the binary representation of the number (i goes from most significant digit to lower), tight denotes wheteher the current number has overshoot the number n or n. See my slow code http://ideone.com/numnIE.
    You can optimize it slightly and get it passed. Basically think in terms of combinatorics, You will get the idea.



Friday, 27 December 2013

Important things in Java


int [] A = new int [n];
for (int x : A) System.out.println (x);

int[] array = new int[4];
Arrays.fill(array, 0);

System.out.println(Arrays.deepToString(array));

Math.max (a, b)
Math.abs (a)

StringBuilder:
StringBuilder res = new StringBuilder ();
res.append (char ('A'));
res.append (String);
String ans = res.toString();

int[] array = new int[4];
Arrays.fill(array, 0);


Arrays.Sort (object[], startIndex, endIndex);

Set st = new HashSet  ();
st.add (5);
st.size();

List  list = new ArrayList  ();
Concerting Set to List type
List  list = new ArrayList  (st);
Collection.sort (list);

String s = new String();
s.toCharArray();

Input Output Code in Java (Code is taken from Egor's library).



-------------------------------------------------------------------------------------------
If you want to use something other, this is Parser class for input (Written by Rudradevbasak's team proof). For output, you can use PrintWriter class which is fast enough.






























Thursday, 26 December 2013

Sliding Window Algorithms and problems related to that..

See the code


Amortized complexity is O(n).

Problems to Solve:
References:

  1. http://people.cs.uct.ac.za/~ksmith/articles/sliding_window_minimum.html
  2. http://softwarelearner.blogspot.in/2011/04/minima-in-sliding-window.html
  3. http://stackoverflow.com/questions/8269916/what-is-sliding-window-algorithm-examples/8269948#8269948
  4. http://richardhartersworld.com/cri/2001/slidingmin.html
  5. http://wcipeg.com/wiki/Sliding_window
  6. http://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/
  7. http://wcipeg.com/wiki/Sliding_range_minimum_query

Using Latex or Mathjax in Blogger




1. To see how any of the formulas were made in any question or answer, including this one, use the "edit" link to view the complete source. To quickly see the source of a single expression, right-click on it and choose "Show Math As > TeX Commands".

    (Note that in some browsers, such as Firefox, the MathJax right-click menu that contains this command will be obscured by the browser's own right-click menu. Click somewhere outside the main browser canvas -- such as in the address bar -- to dismiss the browser menu and reveal the MathJax one behind it).

2. For inline formulas, enclose the formula in `$...$`.  For displayed formulas, use `$$...$$`.  These render differently: $\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{2}$ (inline) or $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{2}\tag{displayed}$$

3. For **Greek letters**, use `\alpha`, `\beta`, …, `\omega`: $\alpha, \beta, … \omega$.  For uppercase, use `\Gamma`, `\Delta`, …, `\Omega`: $\Gamma, \Delta, …, \Omega$.

4. For **superscripts and subscripts**, use `^` and `_`.  For example, `x_i^2`: $x_i^2$.

5. By default, superscripts, subscripts, and other operations apply only to the next "group". A "group" is either a single symbol, or any formula surrounded by curly braces `{`…`}`.  If you do `10^10`, you will get a surprise: $10^10$. But `10^{10}` gives what you probably wanted: $10^{10}$. Use curly braces to delimit a formula to which a superscript or subscript applies: `x^5^6` is an error;  `{x^y}^z` is ${x^y}^z$, and `x^{y^z}` is $x^{y^z}$. Observe the difference between `x_i^2` $x_i^2$ and `x_{i^2}` $x_{i^2}$.

6. **Parentheses** Ordinary symbols `()[]` make parentheses and brackets $(2+3)[4+4]$. Use `\{` and `\}` for curly braces $\{\}$.

    These do *not* scale with the formula in between, so if you write `(\frac12)` the parentheses will be too small: $(\frac12)$.    Using `\left(`…`\right)` will make the sizes adjust automatically to the formula they enclose: `\left(\frac12\right)` is $\left(\frac12\right)$.

   `\left` and`\right` apply to all the following sorts of parentheses: `(` and `)` $(x)$, `[` and `]` $[x]$, `\{` and `\}` $\lbrace x \rbrace$, `|` $|x|$, `\langle` and `\rangle` $\langle x \rangle$,  `\lceil` and `\rceil` $\lceil x \rceil$, and `\lfloor` and `\rfloor` $\lfloor x \rfloor$. There are also invisible parentheses, denoted by `.`: `\left.\frac12\right\rbrace` is $\left.\frac12\right\rbrace$.

7. **Sums and integrals** `\sum` and `\int`; the subscript is the lower limit and the superscript is the upper limit, so for example `\sum_1^n` $\sum_1^n$. Don't forget `{`…`}` if the limits are more than a single symbol.  For example, `\sum_{i=0}^\infty i^2` is $\sum_{i=0}^\infty i^2$. Similarly, `\prod` $\prod$, `\int` $\int$, `\bigcup` $\bigcup$, `\bigcap` $\bigcap$, `\iint` $\iint$.

8. **Fractions** There are two ways to make these. `\frac ab` applies to the next two groups, and produces $\frac ab$; for more complicated numerators and denominators use `{`…`}`: `\frac{a+1}{b+1}` is $\frac{a+1}{b+1}$. If the numerator and denominator are complicated, you may prefer `\over`, which splits up the group that it is in: `{a+1\over b+1}` is ${a+1\over b+1}$.

9. **Fonts** 

  * Use `\mathbb` or `\Bbb` for "blackboard bold": $\mathbb{CHNQRZ}$.
  * Use `\mathbf` for boldface: $\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$  $\mathbf{abcdefghijklmnopqrstuvwxyz}$.
  * Use `\mathtt` for "typewriter" font: $\mathtt{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ $\mathtt{abcdefghijklmnopqrstuvwxyz}$.
  * Use `\mathrm` for roman font: $\mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$  $\mathrm{abcdefghijklmnopqrstuvwxyz}$.
  * Use `\mathcal` for "calligraphic" letters: $\mathcal{ ABCDEFGHIJKLMNOPQRSTUVWXYZ}$ 
  * Use `\mathscr` for script letters: $\mathscr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$
  * Use `\mathfrak` for "Fraktur" (old German style) letters: $\mathfrak{ABCDEFGHIJKLMNOPQRSTUVWXYZ} \mathfrak{abcdefghijklmnopqrstuvwxyz}$.

10. **Radical signs** Use `sqrt`, which adjusts to the size of its argument: `\sqrt{x^3}` $\sqrt{x^3}$; `\sqrt[3]{\frac xy}` $\sqrt[3]{\frac xy}$. For complicated expressions, consider using `{...}^{1/2}` instead.

11. Some special functions such as "lim", "sin", "max", "ln", and so on are normally set in roman font instead of italic font. Use `\lim`, `\sin`, etc. to make these: `\sin x` $\sin x$, not `sin x` $sin x$. Use subscripts to attach a notation to `\lim`: `\lim_{x\to 0}` $$\lim_{x\to 0}$$

12. There are a very large number of special symbols and notations, too many to list here; see [this shorter listing](http://pic.plover.com/MISC/symbols.pdf), or [this exhaustive listing](http://mirror.math.ku.edu/tex-archive/info/symbols/comprehensive/symbols-a4.pdf). Some of the most common include: 
  * `\lt \gt \le \ge \neq` $\lt\, \gt\, \le\, \ge\, \neq$.  You can use `\not` to put a slash through almost anything: `\not\lt` $\not\lt$ but it often looks bad.
  * `\times \div \pm \mp` $\times\, \div\, \pm\, \mp$. `\cdot` is a centered dot: $x\cdot y$
  * `\cup \cap \setminus \subset \subseteq \subsetneq \supset \in \notin \emptyset \varnothing` $\cup\, \cap\, \setminus\, \subset\, \subseteq \,\subsetneq \,\supset\, \in\, \notin\, \emptyset\, \varnothing$ 
  * `{n+1 \choose 2k}` or `\binom{n+1}{2k}` ${n+1 \choose 2k}$ 
  * `\to \rightarrow \leftarrow \Rightarrow \Leftarrow \mapsto` $\to\, \rightarrow\, \leftarrow\, \Rightarrow\, \Leftarrow\, \mapsto$
  * `\land \lor \lnot \forall \exists \top \bot \vdash \vDash` $\land\, \lor\, \lnot\, \forall\, \exists\, \top\, \bot\, \vdash\, \vDash$
  * `\star \ast \oplus \circ \bullet` $\star\, \ast\, \oplus\, \circ\, \bullet$ 
  * `\approx \sim \cong \equiv \prec` $\approx\, \sim \, \cong\, \equiv\, \prec$. 
  * `\infty \aleph_0` $\infty\, \aleph_0$ `\nabla \partial` $\nabla\, \partial$ `\Im \Re` $\Im\, \Re$
  * For modular equivalence, use `\pmod` like this: `a\equiv b\pmod n` $a\equiv b\pmod n$.
  * `\ldots` is the dots in $a_1, a_2, \ldots ,a_n$ `\cdots` is the dots in  $a_1+a_2+\cdots+a_n$
  * Some Greek letters have variant forms:
`\epsilon \varepsilon` $\epsilon\, \varepsilon$, `\phi \varphi` $\phi\, \varphi$, and others. Script lowercase l is `\ell` $\ell$.

  [Detexify](http://detexify.kirelabs.org/classify.html) lets you draw a symbol on a web page and then lists the $\TeX$ symbols that seem to resemble it.  These are not guaranteed to work in MathJax but are a good place to start.

13. **Spaces** MathJax usually decides for itself how to space formulas, using a complex set of rules. Putting extra literal spaces into formulas  will not change the amount of space MathJax puts in: `a␣b` and `a␣␣␣␣b` are  both $a    b$. To add more space, use `\,` for a thin space $a\,b$; `\;` for a wider space $a\;b$.  `\quad` and `\qquad` are large spaces: $a\quad b$, $a\qquad b$.

  To set plain text, use `\text{…}`: $\{x\in s\mid x\text{ is extra large}\}$. You can nest `$…$` inside of `\text{…}`.

14. **Accents and diacritical marks** Use `\hat` for a single symbol $\hat x$, `\widehat` for a larger formula $\widehat{xy}$. If you make it too wide, it will look silly. Similarly, there are `\bar` $\bar x$ and `\overline` $\overline{xyz}$, and `\vec` $\vec x$ and `\overrightarrow` $\overrightarrow{xy}$. For dots, as in $\frac d{dx}x\dot x =  \dot x^2 +  x\ddot x$,  use `\dot` and `\ddot`.

15. Special characters used for MathJax interpreting can be escaped using the `\` character: `\$` $\$$, `\{` $\{$, `\_` $\_$, etc.

(Tutorial ends here.)

-------------

It is important that this note be reasonably short and not suffer from too much bloat. To include more topics, please create short addenda and post them as answers instead of inserting them into this post.

Standard Vieta Jumping and examples

$\sum_{k=1}^n k = \frac{n(n+1)}{2}$

Consider the following equation.
$x^2$ = $y^2 + z^2$.

Consider the first few numbers $x_0$, $x_1$ ,,, $x_n$.

Tuesday, 10 December 2013

2 SAT

Definition:
(x1 v x2) ^ (x1 v -x2) ^ ....
per clause two literals.

Algorithm to found whether there exits a possible assignment or not?
Build implication graph corresponding and then check whether there exists a path from x to -x or not.
If such path exists, then no valid assignment can be done.

Building implication graph
(x v y) add edge -x to y, and -y to x.

Algorithm to find a possible assignment?

First check for the existence case.
for each unassigned literal x, assign it to true and all the y such x -> y, then assign y to true,
Assign all the opposite of these literals to be false.

Implementation:

Problems to practice:
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=43&page=show_problem&problem=2453
http://www.spoj.com/problems/TORNJEVI/
http://www.spoj.com/problems/SUPSUP/
http://2011.nwerc.eu/results.php (Piece it Together ).
http://2012.nwerc.eu/en/results/problems/

References:
http://users.cms.caltech.edu/~umans/cs21/lec17.pdf
http://kartikkukreja.wordpress.com/2013/05/16/solving-2-sat-in-linear-time/
http://classes.soe.ucsc.edu/cmps132/Winter05/hw/hw8sols.pdf
http://apps.topcoder.com/forums/?module=Thread&threadID=803822&start=0&mc=2

Saturday, 7 December 2013

Finding nCk effectively

if n is or range 10^9 or so. and k is of the range <= 20, 50, 100 or so.

Finding nCk % mod:
n * (n - 1) * (n - 2) * (n - k + 1) / (k !).
Do the factorisation of k! easily.
Make an array A such that A[i] = n - i, i >= 0 && i < k.
now for each prime p, let us say it has power q in k!,
Remove q powers of p from A[0] to A[k - 1].

Finally multiply all the A[i]'s and then do mod to get the answer.

 


Another method.
n C k = ((n - 1) C (k - 1) + (n - 1) C k) % mod; when n is odd.
n C k = sum over i = 0 to k. ((n / 2) C i) * ((n / 2) C (k - i)). when n is even.
This method is also included in the code, but it is not so fast :(

Wednesday, 4 December 2013

Important vim commands

  • :! for running a command outside the vim.                   eg. :!pwd
  • set smartindent
  • Ctrl x + Ctrl l                    for autocompletion of entire line
  • Replacing in a line: s/foo/bar/g will replace each occurence of foo by bar.
  • Replacing in a line: s/foo/bar/gc will replace each occurence of foo by bar, but ask for confirmation.
  • Replacing in a file: %s/foo/bar/gc will replace each occurence of foo by bar, but ask for confirmation.
  • But if use s/foo/bar it then it will replace the first occurance of foo by bar in the line.
  • Use arrow keys to get the previous command.
  • Use :ab mail praveendhinwa@gmail.com etc kind of abbreviations.
  • >> and << for indentation
  • sh: temporary returns to unix.
  • e filename: opens the file with given filename.
  • browse e: graphical file opening.
  • use tab for completion of half command too 
  • :g/string/d delete all lines containing string
  • :v/string/d delete all lines not containing string.
  • 2,15s/foo/bar/g delete all occurences of foo by bar from line 2 to 15.
  • * for searching the word under the cursor currently.
  • /word Searching from top
  • ?word Searching from bottom to top.
  • /f[ao]r will search for far and for both.
  • yy for copying a single line.
  • 2yy for copying two lines.
  • y for copying the selected text.
  • p for pasting the clipboard content.
  • shift + [ or ] for moving from the end of functions to start and vice versa.
  • gg for moving the cursor to start of line
  • G for moving the cursor to the end of line.
  • :17 to move the cursor to line numbered 17.
  • 0 Move the cursor to beginning of the line
  • b for start of the word
  • e for moving to end of the word
  • cc for changing an entire line.
  • Generating text to html code.     :%TOhtml
Mapping in Vim:
  • :imap ;so System.out.println() , Whenever you will type ;so, it will autcomplete to System.out.println() with cursor between the paranthesis.

References


Sunday, 22 September 2013

Using Templates in C++ Programming

I would describe about using templates in c++.

  1. functions using templates  

  2. classes using templates  

  3. Template Specialization  
    Template Specialization means that specialize your template for some particular type. eg. you define add function for integers to be integers addition but for strings it may be addition. So You need to define it seperately.

Tuesday, 17 September 2013

My Latest Template for Programming Contests


I have learnt few good things about c++.


  • you can directly use this header file, it will precompile all the header files required.

#include <bits/stdc++.h>
using namespace std;


  • struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

this is meant for reducing slowness of slowness of iostream in syncing. more on
http://codeforces.com/blog/entry/8387
http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_headers.html
http://codeforces.com/blog/entry/925

Precaution: You need to make sure that you do not use scanf and cin statements interchangibly means
one code should exclusively use cin and cout's only if you are using this. Reason is quite obvious.

I have tested the code on codechef. It works great :). Infact slightly faster :)

Here is the link of my latest template:



Sunday, 18 August 2013

Weekend Programming Contest on 17 August 2013 Editorials


Note: For problem M, The editorial is saying that answer is -1 iff n is of form of p^i, Please read it as n is of form of p^i or 2 * p^i.

I have lost the tex file, So I am really sorry, Next time I will try to write editorials in a doc kind of format.

UPDATE1 : Problems have been added to SPOJ and to our Online judge also. http://www2.cse.iitk.ac.in/judge/public/ . So Enjoy solving them :)
http://www.spoj.com/problems/IITKWPCA/
See the problem from A to J, L to O.

UPDATE2: I have corrected the errors in the editorial and uploaded the latest file. If you want some more explantion.I will edit the article, just write a comment about which problem do you think that editorial can be improved and what you do not understand from the editorial.

You can download the latest editorial from this link:

https://docs.google.com/file/d/0B8cc7eHcqRVNaHNWRjl0T01vX1U/edit?usp=sharing

PS: I have updated the editorial, You might face some problems in viewing it in google docs itself. Please download the file and view it.