## UVA online 00151_PowerCrisis

I took a really long time to get this out. I am researching a method to get the solution with some elegant mathematical formula, but it looks like it is took hard to accomplish. So, I used the brute force method that I have, and here it is:

```#include <cstdio>
#include <queue>
#include <map>
using namespace std;

bool isValid(int m, int key, int total){
queue a;
int rmv=0, c=0;

for(int i=0; i<key-1; i++){ a.push(0); }
a.push(1);
for(int i=0; i<total-key; i++){ a.push(0); }

a.pop();
while(a.size()>1 && !rmv){
if(c<(m-1)){
a.push(a.front()); a.pop();
c++;
}else{
rmv = a.front(); a.pop();
c=0;
}
}

return !rmv;
}

int main(){
char line; gets(line);
int t; sscanf(line, "%d", &t);
map<int, int> mem;

while(t){
int m=mem[t];
if(!m){
m = 1;
while(!isValid(m, 13, t)){ m++; }
mem[t] = m;
}
printf("%d\n", m);

gets(line); sscanf(line, "%d", &t);
}

return 0;
}```

## UVA online 11459_SnakeAndLadders

The problem was pretty easy, but there was a trap in the question. It was poorly worded and led to much confusion on the part of the programmers. It was not clearly stated if the process of changing the value takes place before or after the dice roll, which led to WA the first time i tried it.

```#include <cstdio>
#include <map>
using namespace std;

int main(){
char line; gets(line);
int n; sscanf(line, "%d", &n);
while(n--){
int np, nc, nr, end=0; gets(line);
sscanf(line, "%d %d %d", &np, &nc, &nr);

int ps[np];
for(int p=0; p<np; p++){ ps[p]=1; }
map<int, int> cs;

for(int i=0; i<nc; i++){
gets(line);
int a, b; sscanf(line, "%d %d", &a, &b);
cs[a] = b;
}

for(int i=0; i<nr; i++){
gets(line);
int r; sscanf(line, "%d", &r);
int p=i%np;

if(!end){
ps[p] += r;
if(ps[p]>100){ ps[p] = 100; }
while(cs[ps[p]]){ ps[p] = cs[ps[p]]; }

if(ps[p]==100){ end=1; }
}
}

for(int p=0; p<np; p++){
printf("Position of player %d is %d.\n", p+1, ps[p]);
}
}
}```