Problem E
Charged
Background
The electric field $\vec{E}$ of a particle with charge $q$ can be derived from its electric potential $V$:
\[ \vec{E} = \nabla V \]where $\nabla $ is the derivative operator and $V$ at every point in space is
\[ V = {1\over 4\pi \varepsilon _0}{q\over \vec{r}} \]where $\vec{r}$ is the distance from the particle at that point, $1\over 4\pi \varepsilon _0$ is some constant, and $\vec{r} = \sqrt{r_ x^2 + r_ y^2}$ (in a twodimensional plane). The net electric potential at any point is the sum of all of the electric potentials from all the particles.
The force from particle $B$ on particle $A$ is the charge of $A$ $(q_ A)$ multiplied by the electric field from $B$:
\begin{align*} \vec{F}_{B\rightarrow A} & = q_ A\vec{E}_ B\\ & = {1\over 4\pi \varepsilon _0}{q_ A\cdot q_ B\over \vec{r}^2}\hat{r} \end{align*}For this problem, however, you will only visualize the electric potential $V$.
Problem
Given two kinds of particles, those with a positive charge $+e$, and those with negative charges $e$, display the electric potential at every point in space. The electric potential should be normalized relative to ${e\over 4\pi \varepsilon _0}$ (i.e., treat ${e\over 4\pi \varepsilon _0}$ as $1$).
Input
Input starts with $3$ integers $n,m,q$ where $0<n,m\le 50$ and $0<q\le 10$. Then follows $q$ lines: each line contains three values $x,y,s$, where $1 \leq x \leq m$ and $1 \leq y \leq n$ correspond to the integer coordinates of the charged particle and $s$ is the sign of the particle’s charge being either a + or a . No two particles will have the same coordinates.
Output
Your output should be an $n\times m$ grid of ASCII characters oriented with the positive $y$axis pointing down and the positive $x$axis pointing to the right, with coordinates starting from $1$. Every character in the grid corresponds to the total potential at that point.
If the field contains a particle, print either a + or  corresponding to its charge. Otherwise, the character you place will be related to the sign of the potential. If the potential is negative then use the characters {%,X,x}. If it is positive, however, use the character set {0,O,o} (the first element is a zero).
There are $3$ tiers to the field’s magnitude:

$1 / \pi $

$1 / \pi ^2$

$1 / \pi ^3$
If the field is below the third tier print a “.”.
If the magnitude is above the first tier then you would use % or 0 (zero) depending on the sign, if it is below the first tier then you would use X or O, and so on and so forth.
Sample Input 1  Sample Output 1 

20 20 2 5 5 + 15 15  
OOOOOOOOOoooo....... OOOOOOOOOoooo....... OOO000OOOOooo....... OO00000OOOooo....... OO00+00OOOoo........ OO00000OOooo........ OOO000OOOoo....xxxxx OOOOOOOOoo...xxxxxxx OOOOOOOoo...xxxxxxxx ooOOOooo...xxxXXXxxx ooooooo...xxXXXXXXXx oooooo...xxXXXXXXXXX oooo....xxXXX%%%XXXX .......xxxXX%%%%%XXX .......xxXXX%%%%XXX ......xxxXXX%%%%%XXX ......xxxXXXX%%%XXXX ......xxxxXXXXXXXXXX ......xxxxXXXXXXXXXX ......xxxxxXXXXXXXXx 
Sample Input 2  Sample Output 2 

20 20 3 15 15  10 10 + 5 5  
XXXXXXXXXXxxxxxxxxxx XXXXXXXXXXxxxxxxxxxx XXX%%%XXXXxxxxxxxxxx XX%%%%%XXXxxxxxxxxxx XX%%%%XXxxxxxxxxxxx XX%%%%%Xxx..xxxxxxxx XXX%%%Xx.oo..xxxxxxx XXXXXXx.OOOo..xxxxxx XXXXXx.O000Oo.xxxxxx XXXXxxoO0+0OoxxXXXXX xxxxx.oO000O.xXXXXXX xxxxx..oOOO.xXXXXXXX xxxxxx..oo.xX%%%XXXX xxxxxxx..xxX%%%%%XXX xxxxxxxxxxXX%%%%XXX xxxxxxxxxXXX%%%%%XXX xxxxxxxxxXXXX%%%XXXX xxxxxxxxxXXXXXXXXXXX xxxxxxxxxXXXXXXXXXXX xxxxxxxxxXXXXXXXXXXX 
Sample Input 3  Sample Output 3 

20 20 2 10 2 + 10 18  
oooOOOO00000OOOOoooo oooOOOO00+00OOOOoooo oooOOOO00000OOOOoooo ooooOOOO000OOOOooooo oooooOOOOOOOOOoooooo ooooooOOOOOOOoooooo. .oooooooOOOooooooo.. ....ooooooooooo..... .................... .................... .................... ....xxxxxxxxxxx..... .xxxxxxxXXXxxxxxxx.. xxxxxxXXXXXXXxxxxxx. xxxxxXXXXXXXXXxxxxxx xxxxXXXX%%%XXXXxxxxx xxxXXXX%%%%%XXXXxxxx xxxXXXX%%%%XXXXxxxx xxxXXXX%%%%%XXXXxxxx xxxXXXXX%%%XXXXXxxxx 