<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9147331577528336601</id><updated>2024-09-10T07:00:18.579-07:00</updated><category term="uva"/><category term="solution"/><category term="TJU"/><category term="612 - DNA Sorting"/><category term="judge"/><category term="online"/><category term="10010 - Where&#39;s Waldorf?"/><category term="10070 - Leap Year or Not Leap Year and …"/><category term="10082 - WERTYU"/><category term="101 - The Blocks Problem"/><category term="10141 - Request for Proposal"/><category term="10176 - Ocean Deep - Make it shallow"/><category term="10189 - Minesweeper"/><category term="10226 - Hardwood Species"/><category term="10258 - Contest Scoreboard"/><category term="10281 - Average Speed"/><category term="10336 - Rank the Languages"/><category term="10340 - All in All"/><category term="10360 - Rat Attack"/><category term="10363 - Tic Tac Toe"/><category term="10420 - List of Conquests"/><category term="105 - The Skyline Problem"/><category term="10583 - Ubiquitous Religions"/><category term="10608 - Friends"/><category term="10667 - Largest Block"/><category term="10683 - The decadary watch"/><category term="10699 - Count the factors"/><category term="10703 - Free spots"/><category term="10810 - Ultra-QuickSort"/><category term="10827 - Maximum sum on a torus"/><category term="10878 - Decode the tape"/><category term="10901 - Ferry Loading III"/><category term="10903 - Rock-Paper-Scissors Tournament"/><category term="10928 - My Dear Neighbours"/><category term="11034 - Ferry Loading IV"/><category term="11040 - Add bricks in the wall"/><category term="11136 - Hoax or what"/><category term="11223 - O: dah dah dah"/><category term="11308 - Bankrupt Baker"/><category term="11340 - Newspaper"/><category term="11495 - Bubbles and Buckets"/><category term="11520 - Fill the Square"/><category term="11616 - Roman Numerals"/><category term="11636 - Hello World"/><category term="11727 - Cost Cutting"/><category term="11734 - Big Number of Teams will Solve This"/><category term="1178.   Fractal"/><category term="11960 - Divisor Game"/><category term="11988 - Broken Keyboard (a.k.a. Beiju Text)"/><category term="127 - Accordian Patience"/><category term="1406.   The Sierpinski Fractal"/><category term="148 - Anagram checker"/><category term="154 - Recycling"/><category term="263 - Number Chains"/><category term="2841.   Bitwise Reverse"/><category term="291 - The House Of Santa Claus"/><category term="294 - Divisors"/><category term="299 - Train Swapping"/><category term="305 - Joseph"/><category term="336 - A Node Too Far"/><category term="344 - Roman Digititis"/><category term="3517 And Then There Was One"/><category term="353 - Pesky Palindromes"/><category term="374 - Big Mod"/><category term="401 - Palindromes"/><category term="409 - Excuses"/><category term="410 - Station Balance"/><category term="413 - Up and Down Sequences"/><category term="417 - Word Index"/><category term="459 - Graph Connectivity"/><category term="471 - Magic Numbers"/><category term="483 - Word Scramble"/><category term="507 - Jill Rides Again"/><category term="514 - Rails"/><category term="567 - Risk"/><category term="573 - The Snail"/><category term="624 - CD"/><category term="661 - Blowing Fuses"/><category term="673 - Parentheses Balance"/><category term="679 - Dropping Balls"/><category term="725 - Division"/><category term="727 - Equation"/><category term="739 - Soundex Indexing"/><category term="750 - 8 Queens Chess Problem"/><category term="785 - Grid Colouring"/><category term="836 - Largest Submatrix"/><category term="837 - Light and Transparency"/><category term="846 - Steps"/><category term="Count Square"/><category term="Equation"/><category term="Excuses"/><category term="Goldbach&#39;s Conjecture"/><category term="One Little"/><category term="PKU"/><category term="Problem A: Football (aka Soccer)"/><category term="Three Little Endians"/><category term="Two Little"/><category term="friend numbers"/><category term="numeros amigos"/><category term="sin amigos."/><category term="without friends"/><title type='text'>ACM TJU SPOJ Solutions</title><subtitle type='html'>This blog aims to explain some solutions of the online judges</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>104</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-5639336997638341444</id><published>2012-11-22T13:57:00.000-08:00</published><updated>2012-11-22T13:57:48.088-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="417 - Word Index"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>417 - Word Index, uva, solution</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;simple BFS using a queue.&lt;br /&gt;
&lt;pre class=&quot;brush:cpp&quot;&gt;#include &amp;lt;iostream&gt; 
#include &amp;lt;sstream&gt; 
#include &amp;lt;cstring&gt; 
#include &amp;lt;cstdio&gt; 
#include &amp;lt;cstdlib&gt; 
#include &amp;lt;algorithm&gt; 
#include &amp;lt;ctime&gt; 
#include &amp;lt;cctype&gt; 
#include &amp;lt;cmath&gt; 
#include &amp;lt;vector&gt; 
#include &amp;lt;map&gt; 
#include &amp;lt;set&gt; 
#include &amp;lt;queue&gt;
#include&amp;lt;bitset&gt;
#define foreach(it, l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++)
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
using namespace std;
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
 #endif
 string s;
 map&amp;lt;string, int&gt; mapa;
 queue&amp;lt;string&gt; q;
 q.push(&quot;&quot;);
 int cont = 0;
 while (!q.empty()) {
  string val = q.front();
  q.pop();
  mapa[val] = cont++;
  if (val.size() == 5) continue;
  for (char i = (val == &quot;&quot;) ? &#39;a&#39; : val[val.size() - 1] + 1; i &amp;lt; &#39;z&#39; + 1; i++) {
   q.push(val + i);
  }
 }
 char linea[6];
 while (gets(linea)) { 
  printf(&quot;%d\n&quot;, mapa[linea]); 
 }
 return 0;
}

&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/5639336997638341444/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/11/417-word-index-uva-solution.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5639336997638341444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5639336997638341444'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/11/417-word-index-uva-solution.html' title='417 - Word Index, uva, solution'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-9137166513623367959</id><published>2012-11-18T19:21:00.003-08:00</published><updated>2012-11-18T19:21:59.964-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="11520 - Fill the Square"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>11520 - Fill the Square, uva, solution</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;set&gt;
#include&amp;lt;algorithm&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define listar(lista) for (int i = 0; i &amp;lt; lista.size(); i++) db(lista[i])
#define foreach(it, l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++)
using namespace std;
int dirx[] = {0, 0, -1, 1};
int diry[] = {-1, 1, 0, 0};
vector&amp;lt;string&gt; matriz;
int n;
void llenar (int x, int y) {
 if (x &amp;lt; 0 || x &gt;= n || y &amp;lt; 0 || y &gt;= n || matriz[x][y] != &#39;.&#39;) return;
 for (char i = &#39;A&#39;; i &amp;lt; &#39;Z&#39; + 1; i++) {
  bool can = true;
  for (int k = 0; k &amp;lt; 4; k++) {
   if (x + dirx[k] &gt;= 0 &amp;&amp; 
    x + dirx[k] &amp;lt; n &amp;&amp;
    y + diry[k] &gt;= 0 &amp;&amp;
    y + diry[k] &amp;lt; n &amp;&amp; matriz[x + dirx[k]][y + diry[k]] == i)
    can = false;
  }
  if (can)  {
   matriz[x][y] = i;
   break;
  }
 } 
}
int main() {
 int t, caso;
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 scanf(&quot;%d&quot;, &amp;t);
 caso = t;
 while (t--) {
  scanf(&quot;%d&quot;, &amp;n);
  matriz.resize(n);
  for (int i = 0; i &amp;lt; n; i++) {
   cin &gt;&gt; matriz[i];
  }
  for (int i = 0; i &amp;lt; n; i++) {
   for (int j = 0; j &amp;lt; n; j++) {
    llenar(i, j);
   }
  }
  
  printf(&quot;Case %d:\n&quot;, caso - t);
  
  for (int i = 0; i &amp;lt; n; i++) {
   cout &amp;lt;&amp;lt; matriz[i] &amp;lt;&amp;lt; endl;
  }
  
 }
 return 0;
}

&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/9137166513623367959/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/11/11520-fill-square-uva-solution.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/9137166513623367959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/9137166513623367959'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/11/11520-fill-square-uva-solution.html' title='11520 - Fill the Square, uva, solution'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-9059370333064556330</id><published>2012-11-10T15:52:00.001-08:00</published><updated>2012-11-10T15:52:21.121-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="10336 - Rank the Languages"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>10336 - Rank the Languages, uva, solution</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;This can be done with both DFS or BSF graph traversal.&lt;br /&gt;
&lt;pre class=&quot;brush:cpp&quot;&gt;#include &amp;lt;iostream&gt; 
#include &amp;lt;sstream&gt; 
#include &amp;lt;cstring&gt; 
#include &amp;lt;cstdio&gt; 
#include &amp;lt;cstdlib&gt; 
#include &amp;lt;algorithm&gt; 
#include &amp;lt;ctime&gt; 
#include &amp;lt;cctype&gt; 
#include &amp;lt;cmath&gt; 
#include &amp;lt;vector&gt; 
#include &amp;lt;map&gt; 
#include &amp;lt;set&gt; 
#include &amp;lt;queue&gt;
#include&amp;lt;bitset&gt;
#define foreach(it, l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++)
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
using namespace std;
vector&amp;lt;string&gt; lista;
int h, w;
void dfs(int i, int j, char cur) {
 if (i &gt;= 0 &amp;&amp; i &amp;lt; h &amp;&amp; j &gt;= 0 &amp;&amp; j &amp;lt; w &amp;&amp; lista[i][j] == cur) {
  lista[i][j] = &#39;-&#39;;
  dfs(i + 1, j, cur);
  dfs(i - 1, j, cur);
  dfs(i, j - 1, cur);
  dfs(i, j + 1, cur);
 }
}
bool def(int i, int j, char cur) {
 if (i &gt; 0 &amp;&amp; lista[i - 1][j] == cur) return true;
 if (i &amp;lt; h - 1 &amp;&amp; lista[i + 1][j] == cur) return true;
 if (j &gt; 0 &amp;&amp; lista[i][j - 1] == cur) return true;
 if (j &amp;lt; w - 1 &amp;&amp; lista[i][j + 1] == cur) return true;
 return false;
}
bool cmp(const pair&amp;lt;char, int&gt;&amp; a, const pair&amp;lt;char, int&gt;&amp; b) {
 if (a.second &gt; b.second) return true;
 return a.first &amp;lt; b.first;
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int t;
 string s;
 set&amp;lt;char&gt; sc;
 cin &gt;&gt; t;
 int start = t;
 while (t--) {
  cin &gt;&gt; h &gt;&gt; w;
  lista.resize(h);
  for (int i = 0; i &amp;lt; h; i++) {
   cin &gt;&gt; lista[i];
  }
  map&amp;lt;char, int&gt; mapa;
  sc.clear();
  for (int i = 0; i &amp;lt; h; i++) {
   for (int j = 0; j &amp;lt; w; j++) {
    if (lista[i][j] != &#39;-&#39; &amp;&amp; def(i, j, lista[i][j])) {
     char cur = lista[i][j];
     mapa[cur]++;
     sc.insert(cur);
     dfs(i, j, cur);
    }
   }
  }
  printf(&quot;World #%d\n&quot;, start - t);
  vector&amp;lt; pair&amp;lt;char,int&gt; &gt; res;
  foreach(it, mapa) {
   res.push_back(make_pair(it-&gt;first, it-&gt;second));
  }
  sort(res.begin(), res.end(), cmp);
  for (int i = 0; i &amp;lt; res.size(); i++) {
   cout &amp;lt;&amp;lt; res[i].first &amp;lt;&amp;lt; &quot;: &quot; &amp;lt;&amp;lt; res[i].second &amp;lt;&amp;lt; endl;
  }
 }
 return 0;
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/9059370333064556330/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/11/10336-rank-languages-uva-solution.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/9059370333064556330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/9059370333064556330'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/11/10336-rank-languages-uva-solution.html' title='10336 - Rank the Languages, uva, solution'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-1905976714178257619</id><published>2012-10-19T07:39:00.001-07:00</published><updated>2012-11-10T15:53:56.667-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="305 - Joseph"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'> 305 - Joseph, uva, solution</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Just a simple simulation be aware that it would take so much time, &lt;br /&gt;
so as they are just 13 cases then, we calculate them so just will have&lt;br /&gt;
to output the memorized values.&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

 public static int solve(int k) {
  for (int m = 1; ; m++) {
   ArrayList&amp;lt;integer&gt; lista = new ArrayList&amp;lt;integer&gt;();
   for (int i = 1; i &amp;lt;= 2 * k; i++) {
    lista.add(i);
   }
   int idx = (m - 1) % lista.size();
   boolean exito = true;
   while (lista.size() &gt; k &amp;&amp; exito) {
    if (lista.get(idx) &gt; k) {
     lista.remove(idx);
    }
    else exito = false;
    idx += m - 1;
    idx %= lista.size();
   }
   if (exito) return m;
  }
 }
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int res[] = new int[14];
  for (int i = 1; i &amp;lt; 14; i++) {
   res[i] = solve(i);
  }
  int k = sc.nextInt();
  while (k != 0) {
   System.out.println(res[k]); 
   k = sc.nextInt();
  }
 }

}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/1905976714178257619/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/10/305-joseph-uva-solution.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1905976714178257619'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1905976714178257619'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/10/305-joseph-uva-solution.html' title=' 305 - Joseph, uva, solution'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-5996946564453995698</id><published>2012-10-03T14:39:00.000-07:00</published><updated>2012-10-03T14:39:00.629-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="10340 - All in All"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>10340 - All in All, uva, solution</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;utility&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;algorithm&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
using namespace std;

int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 string s, t;
 while (cin &gt;&gt; s &gt;&gt; t) {
  int ss = s.size();
  int tt = t.size();
  if (ss &gt; tt) {
   puts(&quot;No&quot;);
   continue;
  }
  int start = 0;
  bool success = true;
  for (int i = 0; i &amp;lt; ss &amp;&amp; success; i++) {
   while (start &amp;lt; tt &amp;&amp; s[i] != t[start++]) ;
   if (s[i] != t[start - 1]) success = false;
  }
  if (success) puts(&quot;Yes&quot;);
  else puts(&quot;No&quot;);
 }
 return 0;
}

&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/5996946564453995698/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/10/10340-all-in-all-uva-solution.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5996946564453995698'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5996946564453995698'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/10/10340-all-in-all-uva-solution.html' title='10340 - All in All, uva, solution'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-7785126776400400604</id><published>2012-10-03T12:53:00.000-07:00</published><updated>2012-10-03T12:56:39.297-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="410 - Station Balance"/><category scheme="http://www.blogger.com/atom/ns#" term="solution"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'> 410 - Station Balance, uva, solution</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;utility&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;algorithm&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
using namespace std;
bool cmp(const pair&amp;lt;int, int&gt;&amp; a, const pair&amp;lt;int, int&gt;&amp; b) {
 return a.first &amp;lt;= b.first;
}
bool cmp_list(const vector&amp;lt; pair&amp;lt;int, int&gt; &gt;&amp; a, const vector&amp;lt; pair&amp;lt;int, int&gt; &gt;&amp; b) {
 int min_a = 20, min_b = 20;
 for (int i = 0; i &amp;lt; a.size(); i++) {
  if (a[i].second &amp;lt; min_a) min_a = a[i].second;
 }
 for (int i = 0; i &amp;lt; b.size(); i++) {
  if (b[i].second &amp;lt; min_b) min_b = b[i].second;
 }
 return min_a &amp;lt;= min_b;
}
int main() {
 int c, s, cont = 0;
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 while (scanf(&quot;%d %d&quot;, &amp;c, &amp;s) !=EOF) {
  vector&amp;lt; pair&amp;lt;int, int&gt; &gt; lista(2 * c);
  double A = 0;
  for (int i = 0; i &amp;lt; s; i++) {
   scanf(&quot;%d&quot;, &amp;lista[i].first);   
   A += lista[i].first;
   lista[i].second = i;
  }
  for (int i = s; i &amp;lt; 2 * c; i++) {
   lista[i].second  = i;
  }
  A /= c;
  
  sort(lista.begin(), lista.end(), cmp);
  
  double res = 0;
  vector&amp;lt; vector&amp;lt; pair&amp;lt;int, int&gt; &gt; &gt; elementos(c);
  for (int i = 0; i &amp;lt; c; i++) {
   res += fabs(lista[i].first + lista[2 * c - i - 1].first - A); 
   if (lista[i].second &amp;lt; lista[2 * c - i - 1].second) {
    elementos[i].push_back(lista[i]);
    elementos[i].push_back(lista[2 * c - i - 1]);
   }
   else {
    elementos[i].push_back(lista[2 * c - i - 1]);
    elementos[i].push_back(lista[i]);
   }
  }
  printf(&quot;Set #%d\n&quot;, ++cont);
  int n = elementos.size();
  
  sort(elementos.begin(), elementos.end(), cmp_list);
  for (int i = 0; i  &amp;lt; c; i++) {
    printf(&quot;% d:&quot;, i);
    for (int j = 0; j &amp;lt; elementos[i].size(); j++) {
     if (elementos[i][j].first != 0)
     printf(&quot; %d&quot;, elementos[i][j].first);
    }
    puts(&quot;&quot;);
  }
  printf(&quot;IMBALANCE = %.5f\n\n&quot;, res);
 }
 return 0;
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/7785126776400400604/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/10/410-station-balance-uva-solution.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/7785126776400400604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/7785126776400400604'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/10/410-station-balance-uva-solution.html' title=' 410 - Station Balance, uva, solution'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-3961072373038917506</id><published>2012-07-29T13:58:00.005-07:00</published><updated>2012-07-29T13:58:53.371-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="10189 - Minesweeper"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>10189 - Minesweeper, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;cstring&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
using namespace std;
int n, m;
int dx[] = {-1, -1, -1,  0, 0, 1, 1, 1};
int dy[] = {-1,  0,  1, -1, 1, -1, 0, 1};
vector&amp;lt;string&gt; grid;
char tonum(int x, int y) {
 int cont = 0;
 for (int i = 0; i &amp;lt; 8; i++)
  if (x + dx[i] &gt;= 0 &amp;&amp; x + dx[i] &amp;lt; n &amp;&amp; y + dy[i] &gt;= 0 &amp;&amp; y + dy[i] &amp;lt; m)
   if (grid[x + dx[i]][y + dy[i]] == &#39;*&#39;) cont++;
 return cont + &#39;0&#39;;
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 string linea;
 int field = 1;
 cin &gt;&gt; n &gt;&gt; m;
 while (1) {
  for (int i = 0; i &amp;lt; n; i++) {
   cin &gt;&gt; linea;
   grid.push_back(linea);
  }
  for (int i = 0; i &amp;lt; n; i++) 
   for (int j = 0; j &amp;lt; m; j++) 
    if (grid[i][j] != &#39;*&#39;)
     grid[i][j] = tonum(i, j);
  
  cout &amp;lt;&amp;lt; &quot;Field #&quot; &amp;lt;&amp;lt; field++ &amp;lt;&amp;lt; &quot;:&quot;&amp;lt;&amp;lt; endl;
  for (int i = 0; i &amp;lt; n; i++)
   cout &amp;lt;&amp;lt; grid[i] &amp;lt;&amp;lt; endl;
  cin &gt;&gt; n &gt;&gt; m;
  if (n == 0 &amp;&amp; m == 0) break;
  cout &amp;lt;&amp;lt; endl;
  grid.clear();
 }
 return 0;
}

&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/3961072373038917506/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/10189-minesweeper-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/3961072373038917506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/3961072373038917506'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/10189-minesweeper-uva.html' title='10189 - Minesweeper, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-5398701336830974949</id><published>2012-07-17T14:32:00.003-07:00</published><updated>2012-07-17T14:32:57.565-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="11734 - Big Number of Teams will Solve This"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>11734 - Big Number of Teams will Solve This, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include &amp;lt;iostream&gt;
#include &amp;lt;cstdio&gt;
#include &amp;lt;cstring&gt;
#include &amp;lt;vector&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
using namespace std;
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int t;
 scanf(&quot;%d\n&quot;, &amp;t) ;
 char *team, *judge;
 char line[30], line2[30];
 bool wa , pe;
 for (int i = 1; i &amp;lt;= t; i++) {
  gets(line);gets(line2);
  team = line; judge = line2;
  wa = pe = false;
  for ( ; *team &amp;&amp; !wa; team++) {
   if (*team == *judge) {
    judge++;
    continue;
   }
   if(*team == &#39; &#39;) {
    pe = true;
    continue;
   }
   if(*team != *judge) wa = true;
  }
  if (*team != *judge) wa = true;
  
  if (!pe &amp;&amp; !wa)
    printf(&quot;Case %d: Yes\n&quot;, i); 
  else if (wa)
    printf(&quot;Case %d: Wrong Answer\n&quot;, i); 
   else
    printf(&quot;Case %d: Output Format Error\n&quot;, i);     
 }
 return 0;
}

&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/5398701336830974949/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/11734-big-number-of-teams-will-solve.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5398701336830974949'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5398701336830974949'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/11734-big-number-of-teams-will-solve.html' title='11734 - Big Number of Teams will Solve This, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-2521711999719143525</id><published>2012-07-17T13:16:00.003-07:00</published><updated>2012-07-17T13:16:35.271-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="148 - Anagram checker"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>148 - Anagram checker, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;sstream&gt;
#include&amp;lt;algorithm&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;set&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
#define foreach(m, it) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
struct word {
 string str; char trait[26];
 bool operator &gt;= (const word&amp; other) {
  int i = 0;
  for (; i &amp;lt; 26 &amp;&amp; trait[i] &gt;= other.trait[i]; i++);
  return i == 26;
 }
 word&amp; operator -= (const word&amp; other) {
  for (int i = -1; ++i &amp;lt; 26; trait[i] -= other.trait[i]);
  return *this;
 }
 word&amp; operator += (const word&amp; other) {
  for (int i = -1; ++i &amp;lt; 26; trait[i] += other.trait[i]);
  return *this;
 }
};
void genTrait(const char *str, char * trait) {
 for (fill(&amp;trait[0], &amp;trait[26], 0); *str != 0; ++trait[*str++ - &#39;A&#39;]);
}
typedef vector&amp;lt;word&gt;::iterator iterpal;
void searchAnagram(iterpal ini, iterpal fin, word&amp; frase) {
 int i = 0;
 string &amp;str = frase.str;
 for (; i &amp;lt; 26 &amp;&amp; frase.trait[i] == 0; i++);
 if (i == 26) {
  istringstream ss(str);
  vector&amp;lt;string&gt; original, generado;
  for (string word; ss &gt;&gt; word &amp;&amp; word != &quot;=&quot;; original.push_back(word));
  for (string word; ss &gt;&gt; word ; generado.push_back(word));
  sort(original.begin(), original.end());
  if (original != generado) {
   printf(&quot;%s\n&quot;, str.c_str());
  }
  return;
 }
 for (iterpal it = ini; it != fin; it++) {
  if (frase &gt;= *it) {
   frase -= *it;
   str.push_back(&#39; &#39;);
   str.append(it-&gt;str);
   searchAnagram(it + 1, fin, frase);
   str.erase(str.length() - it-&gt;str.length() - 1);
   frase += *it;
  }
 }
 
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 vector&amp;lt;word&gt; dict, subset;
 char line[30];
 for (word palabra; gets(line) != NULL &amp;&amp; line[0] != &#39;#&#39;; ) {
  palabra.str = line;
  genTrait(line, palabra.trait);
  dict.push_back(palabra);
 }
 for (string linea; getline(cin, linea) &amp;&amp; linea != &quot;#&quot;; subset.clear()) {
  word frase = {linea};
  linea.erase(remove(linea.begin(), linea.end(), &#39; &#39;), linea.end());
  if (linea.empty()) continue;
  
  genTrait(linea.c_str(), frase.trait);
  for (iterpal it = dict.begin(); it != dict.end(); it++) {
   if (frase &gt;= *it) {
    subset.push_back(*it);
   }
  }
  frase.str.append(&quot; =&quot;);
  searchAnagram(subset.begin(), subset.end(), frase);
 }
    return 0;
}
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/2521711999719143525/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/148-anagram-checker-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/2521711999719143525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/2521711999719143525'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/148-anagram-checker-uva.html' title='148 - Anagram checker, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-1066878689910105508</id><published>2012-07-13T16:02:00.001-07:00</published><updated>2012-07-13T16:02:40.348-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="263 - Number Chains"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>263 - Number Chains, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;algorithm&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;set&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
#define foreach(m, it) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
int n;
bool espali(string linea) {
 int n = linea.size();
 for (int i = 0; i &amp;lt; n / 2; i++) {
  if (linea[i] != linea[n - i - 1])
   return false;
 }
 return true;
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 string s;
 char buf[10];
 int mayor, menor, prev, len;
 set&amp;lt;int&gt; nums;
 while (cin &gt;&gt; s) {
  if (s == &quot;0&quot;) break;
  prev = -1;
  len = 0;
  nums.clear();
  printf(&quot;Original number was %s\n&quot;, s.c_str());
  while (true) {
   sort(s.rbegin(), s.rend());
   mayor = atoi(s.c_str());
   reverse(s.begin(), s.end());
   menor = atoi(s.c_str());
   printf(&quot;%d - %d = %d\n&quot;, mayor, menor, mayor - menor);
   len++;
   prev = mayor - menor;
   if (!nums.count(prev))
    nums.insert(prev);
   else break;
   sprintf(buf, &quot;%d&quot;, prev);
   s = buf;
  }
  printf(&quot;Chain length %d\n\n&quot;, len);
 }
 return 0;
}

&lt;/pre&gt;&lt;a href=&quot;http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=24&amp;page=show_problem&amp;problem=199&quot;&gt;Here is the Statement&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/1066878689910105508/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/263-number-chains-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1066878689910105508'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1066878689910105508'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/263-number-chains-uva.html' title='263 - Number Chains, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-818437753414253410</id><published>2012-07-13T14:07:00.001-07:00</published><updated>2012-07-13T14:07:41.891-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="353 - Pesky Palindromes"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>353 - Pesky Palindromes, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;set&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
#define foreach(m, it) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
int n;
bool espali(string linea) {
 int n = linea.size();
 for (int i = 0; i &amp;lt; n / 2; i++) {
  if (linea[i] != linea[n - i - 1])
   return false;
 }
 return true;
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 char linea[100];
 set&amp;lt;string&gt; s;
 while (gets(linea) != NULL) {
  int n = strlen(linea);
  s.clear();
  for (int i = 0; i &amp;lt; n; i++) {
   for (int j = i; j &amp;lt; n; j++) {
    string aux = string(linea).substr(i, j - i + 1);
    if (espali(aux))
     s.insert(aux);
   }
  }
  printf(&quot;The string &#39;%s&#39; contains %d palindromes.\n&quot;, linea , s.size());
 }
 return 0;
}

&lt;/pre&gt;&lt;a href=&quot;http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=24&amp;page=show_problem&amp;problem=289&quot;&gt;Here is the Statement&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/818437753414253410/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/353-pesky-palindromes-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/818437753414253410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/818437753414253410'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/353-pesky-palindromes-uva.html' title='353 - Pesky Palindromes, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-4090896768437473879</id><published>2012-07-13T13:24:00.000-07:00</published><updated>2012-07-13T13:24:15.762-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="409 - Excuses"/><category scheme="http://www.blogger.com/atom/ns#" term="Excuses"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>409 - Excuses, Excuses, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;set&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
#define foreach(m, it) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
string limpiar(string s) {
 int n = s.size();
 for (int i = 0; i &amp;lt; n; i++) {
  if (!isalpha(s[i])) s[i] = &#39; &#39;;
  else s[i] = tolower(s[i]);
 }
 return s;
}
bool contain(vector&amp;lt;string&gt; &amp; lista, string keyword) {
 int n = lista.size();
 for (int i = 0; i &amp;lt; n; i++) {
  if (lista[i] == keyword)
   return true;
 }
 return false;
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int k, x;
 vector&amp;lt;string&gt; keywords;
 map&amp;lt;string, int&gt; excuses;
 char keyword[40], excuse[100];
 int cont = 1;
 while (scanf(&quot;%d %d\n&quot;, &amp;k, &amp;x) != EOF) {
  keywords.clear();
  excuses.clear();
  for (int i = 0; i &amp;lt; k; i++) {
   gets(keyword);
   keywords.push_back(keyword);
  }
  for (int i = 0; i &amp;lt; x; i++) {
   gets(excuse);
   excuses[(string)excuse];
  }
  int best = 0;
  foreach(excuses, it) {
   string cad = limpiar(it-&gt;first);
   char *st, *buf, sep[] = &quot; &quot;;
   buf = strdup(cad.c_str());
   st = strtok(buf, sep);
   while (st) {
    if (contain(keywords, st))
     it-&gt;second++;
    st = strtok(0, sep);
   }
   best = max(it-&gt;second, best);
  }
  printf(&quot;Excuse Set #%d\n&quot;, cont++);
  foreach(excuses, it) {
   if (it-&gt;second == best)
    printf(&quot;%s\n&quot;, it-&gt;first.c_str());
  }
  puts(&quot;&quot;);
 }
 return 0;
}
&lt;/pre&gt;&lt;a href=&quot;http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=24&amp;page=show_problem&amp;problem=350&quot;&gt;Here is the Statement&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/4090896768437473879/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/409-excuses-excuses-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/4090896768437473879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/4090896768437473879'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/409-excuses-excuses-uva.html' title='409 - Excuses, Excuses, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-7025306334764549602</id><published>2012-07-13T12:47:00.002-07:00</published><updated>2012-07-13T12:47:22.053-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="401 - Palindromes"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>401 - Palindromes, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class = &quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;set&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
#define foreach(it, m) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
map&amp;lt;char, char&gt; m;
bool espali(string s) {
 int n = s.size();
 for (int i = 0; i &amp;lt; n / 2; i++) {
  if (s[i] != s[n - i - 1])
   return false;
 }
 return true;
}
bool esmirror(string s) {
 int n = s.size();
 for (int i = 0; i &amp;lt;= n / 2; i++)
  if (s[i] != m[s[n - i - 1]])
   return false;
 return true;
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 char s[30];
 m[&#39;A&#39;] = &#39;A&#39;; m[&#39;M&#39;] = &#39;M&#39;; m[&#39;Y&#39;] = &#39;Y&#39;;
 m[&#39;B&#39;] = &#39;-&#39;; m[&#39;N&#39;] = &#39;-&#39;; m[&#39;Z&#39;] = &#39;5&#39;;
 m[&#39;C&#39;] = &#39;-&#39;; m[&#39;O&#39;] = &#39;O&#39;; m[&#39;1&#39;] = &#39;1&#39;;
 m[&#39;D&#39;] = &#39;-&#39;; m[&#39;P&#39;] = &#39;-&#39;; m[&#39;2&#39;] = &#39;S&#39;;
 m[&#39;E&#39;] = &#39;3&#39;; m[&#39;Q&#39;] = &#39;-&#39;; m[&#39;3&#39;] = &#39;E&#39;;
 m[&#39;F&#39;] = &#39;-&#39;; m[&#39;R&#39;] = &#39;-&#39;; m[&#39;4&#39;] = &#39;-&#39;;
 m[&#39;G&#39;] = &#39;-&#39;; m[&#39;S&#39;] = &#39;2&#39;; m[&#39;5&#39;] = &#39;Z&#39;;
 m[&#39;H&#39;] = &#39;H&#39;; m[&#39;T&#39;] = &#39;T&#39;; m[&#39;6&#39;] = &#39;-&#39;;
 m[&#39;I&#39;] = &#39;I&#39;; m[&#39;U&#39;] = &#39;U&#39;; m[&#39;7&#39;] = &#39;-&#39;;
 m[&#39;J&#39;] = &#39;L&#39;; m[&#39;V&#39;] = &#39;V&#39;; m[&#39;8&#39;] = &#39;8&#39;;
 m[&#39;K&#39;] = &#39;-&#39;; m[&#39;W&#39;] = &#39;W&#39;; m[&#39;9&#39;] = &#39;-&#39;;
 m[&#39;L&#39;] = &#39;J&#39;; m[&#39;X&#39;] = &#39;X&#39;; 
 bool pali, mirror;
 while(gets(s) != NULL) {
  pali = espali(s);
  mirror = esmirror(s);
  if (pali &amp;&amp; mirror)
   printf(&quot;%s -- is a mirrored palindrome.\n&quot;, s);
  else 
   if (pali) 
    printf(&quot;%s -- is a regular palindrome.\n&quot;, s);
   else
    if (mirror)
     printf(&quot;%s -- is a mirrored string.\n&quot;, s);
    else
     printf(&quot;%s -- is not a palindrome.\n&quot;, s);
  puts(&quot;&quot;);
 }
 return 0;
}

&lt;/pre&gt;&lt;a href=&quot;http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=24&amp;page=show_problem&amp;problem=342&quot;&gt; here is the statement&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/7025306334764549602/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/401-palindromes-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/7025306334764549602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/7025306334764549602'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/401-palindromes-uva.html' title='401 - Palindromes, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-8757794473740815213</id><published>2012-07-12T16:11:00.003-07:00</published><updated>2012-07-12T16:13:21.701-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="10878 - Decode the tape"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>10878 - Decode the tape, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;set&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
#define foreach(it, m) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 char s[20];
 while (gets(s) != NULL) {
  if (s[0] == &#39;_&#39;) continue;
  int mask = 0;
  for (int i = 8; i &gt;= 4; i--) {
   if (s[9 - i] == &#39;o&#39;) mask |= 1 &amp;lt;&amp;lt; (i - 1);
  }
  for (int i = 2; i &gt;= 0; i--) {
   if (s[9 - i] == &#39;o&#39;) mask |= 1 &amp;lt;&amp;lt; i;
  }
  printf(&quot;%c&quot;, (char)mask);
 }
 return 0;
}
&lt;/pre&gt;&lt;a href=&quot;http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=24&amp;page=show_problem&amp;problem=1819&quot; target=&quot;_blank&quot;&gt; here is the statement&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/8757794473740815213/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/10878-decode-tape-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/8757794473740815213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/8757794473740815213'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/10878-decode-tape-uva.html' title='10878 - Decode the tape, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-5724032738695794590</id><published>2012-07-12T15:09:00.001-07:00</published><updated>2012-07-12T15:09:09.609-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="471 - Magic Numbers"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>471 - Magic Numbers, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;set&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
#define foreach(it, m) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
bool has_repeated_digits(long long int s) {
 int mask = 0;
 while (s) {
  if (mask &amp; (1 &amp;lt;&amp;lt; (s % 10)))
   return true;
  mask |= 1 &amp;lt;&amp;lt; (s % 10);
  s /= 10;
 }
 return false;
}

int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int t;
 long long int max_s1 = 9876543210, s1, s2, max_s2, N;
 scanf(&quot;%d&quot;, &amp;t);
 for (; t--;) {
  scanf(&quot;%lld&quot;, &amp;N);
  max_s2 = max_s1 / N;
  for (s2 = 1; s2 &amp;lt;= max_s2; s2++) {
   if (has_repeated_digits(s2)) continue;
   s1 = s2 * N;
   if (has_repeated_digits(s1)) continue;
   printf(&quot;%lld / %lld = %lld\n&quot;, s1, s2, N);
  }
  if (t)
   puts(&quot;&quot;);
 }
 return 0;
}

&lt;/pre&gt;&lt;a href=&quot;http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=24&amp;page=show_problem&amp;problem=412&quot; target=&quot;_blank&quot;&gt;here is the statement&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/5724032738695794590/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/471-magic-numbers-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5724032738695794590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5724032738695794590'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/07/471-magic-numbers-uva.html' title='471 - Magic Numbers, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-8619662212385935886</id><published>2012-06-20T12:33:00.001-07:00</published><updated>2012-06-20T12:35:16.831-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="846 - Steps"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>846 - Steps, UVA</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
#define foreach(it, m) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  //freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int x, y;
 int t;
 scanf(&quot;%d&quot;, &amp;t);
 //db(t);
 for (int i = 0; i &amp;lt; t; i++) {
  scanf(&quot;%d%d&quot;, &amp;x , &amp;y);
  //db2(x, y);
  if (x == y) {
   puts(&quot;0&quot;);
   continue;
  }
  int n = (int)sqrt(y - x);
  //db(n);
  if (n * n == y - x)
   n = 2 * n - 1;
  else
   if (n * (n + 1) &amp;lt; y - x) {
    n = 2 * n + 1;
   }
   else n = 2 * n;
  /*db2(x, y);
  db(n);*/
  printf(&quot;%d\n&quot;, n);
 }
 return 0;
}

&lt;/pre&gt;a good explanation can be found here&lt;br /&gt;
&lt;a href=&quot;http://www.algorithmist.com/index.php/UVa_846#846_-_Steps&quot; target=&quot;_black&quot;&gt;Algorithmist&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/8619662212385935886/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/06/846-steps-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/8619662212385935886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/8619662212385935886'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/06/846-steps-uva.html' title='846 - Steps, UVA'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-5446345103275608999</id><published>2012-04-18T23:30:00.002-07:00</published><updated>2012-04-18T23:30:21.153-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="1406.   The Sierpinski Fractal"/><category scheme="http://www.blogger.com/atom/ns#" term="judge"/><category scheme="http://www.blogger.com/atom/ns#" term="online"/><category scheme="http://www.blogger.com/atom/ns#" term="TJU"/><title type='text'>1406.   The Sierpinski Fractal, tju online judge</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &lt;&lt; #a &lt;&lt; &quot; = &quot; &lt;&lt; a &lt;&lt; endl
#define db2(a, b) \
cout &lt;&lt; #a &lt;&lt; &quot; = &quot; &lt;&lt; a &lt;&lt; &quot; &quot; &lt;&lt; #b &lt;&lt; &quot; = &quot; &lt;&lt; b &lt;&lt; endl
#define inf (1&lt;&lt;30)
#define foreach(it, m) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
#define MAX 2048
using namespace std;
char M[MAX][MAX];
void solve(int n, int v, int h) {
 if (n == 1) {
  M[v][h] = &#39;/&#39;;
  M[v - 1][h + 1] = &#39;/&#39;;
  M[v - 1][h + 2] = &#39;\\&#39;;
  M[v][h + 1] = &#39;_&#39;;
  M[v][h + 2] = &#39;_&#39;;
  M[v][h + 3] = &#39;\\&#39;;
 }
 else {
  solve(n - 1, v, h);
  solve(n - 1, v - pow(2., n - 1), h + pow(2., n - 1));
  solve(n - 1, v, h + pow(2., n));
 } 
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int n;
 for (int i = 0; i &amp;lt; MAX; i++) {
  for (int j = 0; j &amp;lt; MAX; j++) {
   M[i][j] = &#39; &#39;;
  }
 }
 string linea = &quot;&quot;;
 while (scanf(&quot;%d&quot;, &amp;n) != EOF &amp;&amp; n != 0) {
  for (int i = 0; i &amp;lt; pow(2., n + 1); i++) {
   for (int j = 0; j &amp;lt; pow(2., n + 1); j++) {
    M[i][j] = &#39; &#39;;
   }
  }
  solve(n, pow(2., n) - 1, 0);
  for (int i = 0; i &amp;lt; pow(2., n) ; i++) {
   linea = &quot;&quot;;
   for (int j = 0; j &amp;lt; pow(2., n + 1); j++) {
    if (M[i][j] != &#39; &#39;) {
     printf(&quot;%s%c&quot;,linea.c_str(), M[i][j]);
     linea = &quot;&quot;;
    }
    else linea += &quot; &quot;;
   }
   puts(&quot;&quot;);
  }
  puts(&quot;&quot;);
 }
 return 0;
}

&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/5446345103275608999/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/1406-sierpinski-fractal-tju-online.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5446345103275608999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5446345103275608999'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/1406-sierpinski-fractal-tju-online.html' title='1406.   The Sierpinski Fractal, tju online judge'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-1198515155928650708</id><published>2012-04-18T22:25:00.001-07:00</published><updated>2012-04-18T22:25:21.017-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="1178.   Fractal"/><category scheme="http://www.blogger.com/atom/ns#" term="judge"/><category scheme="http://www.blogger.com/atom/ns#" term="online"/><category scheme="http://www.blogger.com/atom/ns#" term="TJU"/><title type='text'>1178.   Fractal, tju online judge</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cmath&gt;
#include&amp;lt;map&gt;
#define db(a) \
cout &lt;&lt; #a &lt;&lt; &quot; = &quot; &lt;&lt; a &lt;&lt; endl
#define db2(a, b) \
cout &lt;&lt; #a &lt;&lt; &quot; = &quot; &lt;&lt; a &lt;&lt; &quot; &quot; &lt;&lt; #b &lt;&lt; &quot; = &quot; &lt;&lt; b &lt;&lt; endl
#define inf (1&lt;&lt;30)
#define foreach(it, m) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
#define MAX 729
using namespace std;
char M[MAX][MAX];
void solve(int n, int v, int h) {
 if (n == 1) {
  M[v][h] = &#39;X&#39;;
 }
 else {
  solve(n - 1, v - pow(3., n - 2), h - pow(3., n - 2));
  solve(n - 1, v - pow(3., n - 2), h + pow(3., n - 2));
  solve(n - 1, v, h);
  solve(n - 1, v + pow(3., n - 2), h - pow(3., n - 2));
  solve(n - 1, v + pow(3., n - 2), h + pow(3., n - 2));
 } 
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int n = 7;
 for (int i = 0; i &amp;lt; MAX; i++) {
  for (int j = 0; j &amp;lt; MAX; j++) {
   M[i][j] = &#39; &#39;;
  }
 }
 string linea;
 solve(n, (int)pow(3., n - 1) / 2, (int)pow(3., n - 1) / 2);
 while (scanf(&quot;%d&quot;, &amp;n) != EOF) {
  if (n == -1) break;
  for (int i = 0; i &amp;lt; pow(3., n - 1) ; i++) {
   linea = &quot;&quot;;
   for (int j = 0; j &amp;lt; pow(3., n - 1); j++) {
    if (M[i][j] != &#39;X&#39;)
     linea += &quot; &quot;;
    else {
     printf(&quot;%sX&quot;, linea.c_str());
     linea = &quot;&quot;;
    }
   }
   puts(&quot;&quot;);
  }
  puts(&quot;-&quot;);
 }
 return 0;
}

&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/1198515155928650708/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/1178-fractal-tju-online-judge.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1198515155928650708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1198515155928650708'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/1178-fractal-tju-online-judge.html' title='1178.   Fractal, tju online judge'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-1026949391584484025</id><published>2012-04-17T09:27:00.002-07:00</published><updated>2012-04-21T17:54:32.012-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="10827 - Maximum sum on a torus"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>10827 - Maximum sum on a torus, uva</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;cstdio&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;iostream&gt;
#define db(a) cout &lt;&lt; #a &lt;&lt; &quot; = &quot; &lt;&lt; a &lt;&lt; endl
#define db2(a, b) cout &lt;&lt; #a &lt;&lt; &quot; = &quot; &lt;&lt; a &lt;&lt; &quot; &quot; &lt;&lt; #b &lt;&lt; &quot; = &quot; &lt;&lt; b &lt;&lt; endl
#define db3(a, b, c) cout &lt;&lt; #a &lt;&lt; &quot; = &quot; &lt;&lt; a &lt;&lt; &quot; &quot; &lt;&lt; #b &lt;&lt; &quot; = &quot; &lt;&lt; b &lt;&lt; &quot; &quot; &lt;&lt; #c &lt;&lt; &quot; = &quot; &lt;&lt; c &lt;&lt; endl
using namespace std;
int main() {
 #ifdef dennisbot
 freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
 //freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int m ,n;
 scanf(&quot;%d&quot;, &amp;m);
 while (m --) {
  scanf(&quot;%d&quot;, &amp;n);
  int matriz[n][n], fila[n];
  for (int i = 0; i &amp;lt; n; i++) {
   for (int j = 0; j &amp;lt; n; j++) {
    scanf(&quot;%d&quot;, &amp;matriz[i][j]);
   }
  }
  /*for (int i = 0; i &amp;lt; n; i++) {
   for (int j = 0; j &amp;lt; n; j++) {
    if (j != 0) cout &lt;&lt; &quot; &quot;;
    cout &lt;&lt; matriz[i][j];
   }
   cout &lt;&lt; endl;
  }*/
  int sum = 0, sum_min = 0,total = 0, var, max = -1000, min = 1000;
  for (int i = 0; i &amp;lt; n; i++) {
   memset(fila, 0, sizeof fila);
   for (int ii = i; ii &amp;lt; i + n; ii++) {
    sum = sum_min = total = 0;
    min = 1000;
    for (int j = 0; j &amp;lt; n; j++) {
     fila[j] += matriz[ii % n][j];
     total += fila[j];
     if (sum &gt;= 0) {
      sum += fila[j];
     }
     else sum = fila[j];
     if (sum_min &lt;= 0) {
      sum_min += fila[j];
     }
     else sum_min = fila[j];
     if (sum &gt; max) max = sum;
     if (sum_min &amp;lt; min) min = sum_min;
    }
    max = std::max(max, total - min);
   }
   
  }
  printf(&quot;%d\n&quot;, max);
 }
 return 0;
}

&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/1026949391584484025/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/10827-maximum-sum-on-torus-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1026949391584484025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1026949391584484025'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/10827-maximum-sum-on-torus-uva.html' title='10827 - Maximum sum on a torus, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-4631808488723679826</id><published>2012-04-08T08:38:00.001-07:00</published><updated>2012-04-08T08:39:51.089-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="11636 - Hello World"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>11636 - Hello World, uva</title><content type='html'>&lt;pre class=&quot;brush:cpp&quot;&gt;#include &amp;lt;iostream&gt;
#include &amp;lt;cstdio&gt;
#include &amp;lt;cstdlib&gt;
#include &amp;lt;cstring&gt;
#include &amp;lt;ctime&gt;
#include &amp;lt;vector&gt;
#include &amp;lt;stdio.h&gt;
#define db(a) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) \
cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define inf (1&amp;lt;&amp;lt;30)
using namespace std;
int lista[10001];
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
 #endif
 int seed = 1, cont = 0, t = 1;
 for (int i = 1; i &amp;lt; 10001; i++) {
  if (seed &gt;= i) {
   lista[i] = cont;
  }
  else {
   while (seed *= 2, cont++, seed &amp;lt; i);
   lista[i] = cont;
  }
 }
 int n;
 while (scanf(&quot;%d&quot;, &amp;n) != EOF &amp;&amp; n &gt; 0) {
  printf(&quot;Case %d: %d\n&quot;, t++, lista[n]); 
 }
    return 0;
}


&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/4631808488723679826/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/11636-hello-world-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/4631808488723679826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/4631808488723679826'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/11636-hello-world-uva.html' title='11636 - Hello World, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-7952852741351859234</id><published>2012-04-01T10:02:00.000-07:00</published><updated>2012-04-01T10:02:00.392-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="679 - Dropping Balls"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>679 - Dropping Balls, uva</title><content type='html'>&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;utility&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
using namespace std;
int bin_to_entero(string binario) {
 int n = binario.size();
 int t = 1, res = 0;
 for (int i = n - 1; i &gt;= 0; i--) {
  res += t * (binario[i] - 48);
  t *= 2;
 }
 return res;
}
int main() {
 vector&amp;lt; vector&amp;lt;string&gt; &gt; level;
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 vector&amp;lt;string&gt; seed;
 seed.push_back(&quot;10&quot;);
 seed.push_back(&quot;11&quot;);
 level.push_back(seed);
 int t = 2;
 for (int k = 3; k &amp;lt; 21; k++) {
  vector&amp;lt;string&gt; fila;
  for (int i = 0; i &amp;lt; t; i++) {
   fila.push_back(level[k - 3][i] + &quot;0&quot;);
  }
  for (int i = 0; i &amp;lt; t; i++) {
   fila.push_back(level[k - 3][i] + &quot;1&quot;);
  }
  level.push_back(fila);
  t *= 2;
 }
 int n, D, I;
 scanf(&quot;%d&quot;, &amp;n);
 for (int i = 0; i &amp;lt; n; i++) {
  scanf(&quot;%d%d&quot;, &amp;D, &amp;I);
  printf(&quot;%d\n&quot;, bin_to_entero(level[D - 2][I - 1]));
 }
 scanf(&quot;%d&quot;, &amp;n);
 return 0;
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/7952852741351859234/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/679-dropping-balls-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/7952852741351859234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/7952852741351859234'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/679-dropping-balls-uva.html' title='679 - Dropping Balls, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-7803342584761036525</id><published>2012-04-01T05:12:00.002-07:00</published><updated>2012-04-01T05:12:22.434-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="785 - Grid Colouring"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>785 - Grid Colouring, uva</title><content type='html'>&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;utility&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
using namespace std;
vector&amp;lt;string&gt; grilla;
vector&amp;lt; pair&amp;lt;int, int&gt; &gt; m;
void dfs(char marcar,int x, int y) {
 if (x &gt;= 0 &amp;&amp; x &amp;lt; grilla.size() 
 &amp;&amp; y &gt;= 0 &amp;&amp; y &amp;lt; grilla[x].size() 
 &amp;&amp; grilla[x][y] == 32) {
  grilla[x][y] = marcar;
  dfs(marcar, x - 1, y);
  dfs(marcar, x, y - 1);
  dfs(marcar, x + 1, y);
  dfs(marcar, x, y + 1); 
 }
}
int main() {
 
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int len = 0;
 char linea[100];
 while (gets(linea) != NULL) {
  if (linea[0] == &#39;_&#39;) {
   int n = m.size();
   for (int i = 0; i &amp;lt; n; i++) {
    char marcar = grilla[m[i].first][m[i].second];
    grilla[m[i].first][m[i].second] = 32;
    dfs(marcar, m[i].first, m[i].second);
   }
   n = grilla.size();
   for (int i = 0; i &amp;lt; n; i++) {
    printf(&quot;%s\n&quot;, grilla[i].c_str());
   }
   puts(linea);
   grilla.clear();
   m.clear();
   continue;
  }
  len = strlen(linea);
  for (int i = 0; i &amp;lt; len; i++) {
   if (linea[i] != 32 &amp;&amp; linea[i] != &#39;X&#39;)
    m.push_back(make_pair(grilla.size(), i));
  }
  grilla.push_back(linea);
 }
 return 0;
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/7803342584761036525/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/785-grid-colouring-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/7803342584761036525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/7803342584761036525'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/04/785-grid-colouring-uva.html' title='785 - Grid Colouring, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-5860460033144166031</id><published>2012-03-31T19:46:00.003-07:00</published><updated>2012-03-31T19:46:53.386-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="413 - Up and Down Sequences"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>413 - Up and Down Sequences,  UVA</title><content type='html'>&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;set&gt;
#include&amp;lt;algorithm&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define listar(lista) for (int i = 0; i &amp;lt; lista.size(); i++) db(lista[i])
using namespace std;
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
 #endif
 int aveup = 0, avedown = 0;
 double  sumup = 0, sumdown = 0;
 int creciente = 0, decreciente = 0;
 bool first = true, crece = true, decrece = true;
 int d, leido, cont = 0;
 while (scanf(&quot;%d&quot;, &amp;d) != EOF) {
  if (d != 0) {
   cont++;
   if (first) {
    leido = d;
    first = false;
    continue;
   }
   if (leido == d) {
    if (crece)
     creciente++;
    if (decrece)
     decreciente++;
    leido = d;
    continue;
   }
   if (leido &amp;lt; d) {
    if (decrece) {
     if (creciente != decreciente) {
      sumdown += decreciente;
      avedown++;
     }
     decrece = false;
     decreciente = 0;
    }
    crece = true;
    creciente++;
    leido = d;
    continue;
   }
   if (leido &gt; d) {
    if (crece) {
     if(creciente != decreciente) {
      sumup += creciente;
      aveup++;
     }
     crece = false;
     creciente = 0;
    }
    decrece = true;
    decreciente++;
    leido = d;
   }
  }
  else {
   if (cont == 0) break;
   if (creciente == decreciente)
    printf(&quot;Nr values = %d:  %.6f %.6f\n&quot;, cont, 0. , 0.);
   else {
    if (crece) sumup += creciente, aveup++;
    if (decrece) sumdown += decreciente, avedown++;
    printf(&quot;Nr values = %d:  %.6f %.6f\n&quot;,cont , (aveup != 0) ? sumup / aveup : 0, (avedown != 0) ? sumdown / avedown : 0);
   }
   creciente = decreciente = leido = cont = 0;
   first = crece = decrece = true;
   sumdown = sumup = aveup = avedown = 0;
  }
 }
 return 0;
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/5860460033144166031/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/03/413-up-and-down-sequences-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5860460033144166031'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/5860460033144166031'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/03/413-up-and-down-sequences-uva.html' title='413 - Up and Down Sequences,  UVA'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-1054575550025460780</id><published>2012-03-31T18:24:00.003-07:00</published><updated>2012-03-31T18:24:42.667-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="567 - Risk"/><category scheme="http://www.blogger.com/atom/ns#" term="uva"/><title type='text'>567 - Risk, uva</title><content type='html'>&lt;pre class=&quot;brush:cpp&quot;&gt; #include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;queue&gt;
#include&amp;lt;vector&gt;
#include&amp;lt;map&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define db2(a, b) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot; &quot; #b &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; b &amp;lt;&amp;lt; endl
#define foreach(mapa, it) for (typeof(mapa.begin()) it = mapa.begin(); it != mapa.end(); it++)
using namespace std;
map&amp;lt;int, vector&amp;lt;int&gt; &gt; adyacencia;
map&amp;lt;int, int&gt; dist;
void bfs(int a, int b) {
 queue&amp;lt;int&gt; q;
 q.push(a);
 dist.clear();
 dist[a] = 0;
 while (!q.empty()) {
  int u = q.front(); q.pop();
  if (u == b) {
   printf(&quot;%2d to %2d: %d\n&quot;, a, b, dist[b]); 
   break;
  }
  for (int i = 0; i &amp;lt; adyacencia[u].size(); i++) {
   if (dist.count(adyacencia[u][i])) continue;
   dist[adyacencia[u][i]] = dist[u] + 1;
   q.push(adyacencia[u][i]);
  }
 }
}
int main() {
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
  freopen(&quot;ou.out&quot;, &quot;w&quot;, stdout);
 #endif
 int n, var, ini, fin, cont = 1, ret;
 while (1) {
  adyacencia.clear();
  dist.clear();
  for (int i = 1; i &amp;lt; 20; i++) {
   ret = scanf(&quot;%d&quot;, &amp;n);
   if (ret == EOF) return 0;
   for (int j = 0; j &amp;lt; n; j++) {
    scanf(&quot;%d&quot;, &amp;var);
    adyacencia[i].push_back(var);
    adyacencia[var].push_back(i);
   }
  }
  scanf(&quot;%d&quot;, &amp;n);
  printf(&quot;Test Set #%d\n&quot;, cont++);
  for (int i = 0; i &amp;lt; n; i++) {
   scanf(&quot;%d&quot;, &amp;ini);
   scanf(&quot;%d&quot;, &amp;fin);
   bfs(ini, fin);
  }
  puts(&quot;&quot;);
 }
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/1054575550025460780/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/03/567-risk-uva.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1054575550025460780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1054575550025460780'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/03/567-risk-uva.html' title='567 - Risk, uva'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9147331577528336601.post-1828927717752606839</id><published>2012-03-30T11:12:00.003-07:00</published><updated>2012-03-30T11:12:38.163-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="2841.   Bitwise Reverse"/><category scheme="http://www.blogger.com/atom/ns#" term="TJU"/><title type='text'>2841.   Bitwise Reverse, tju</title><content type='html'>&lt;pre class=&quot;brush:cpp&quot;&gt;#include&amp;lt;iostream&gt;
#include&amp;lt;cstdio&gt;
#include&amp;lt;cstring&gt;
#include&amp;lt;algorithm&gt;
#include&amp;lt;vector&gt;
#define db(a) cout &amp;lt;&amp;lt; #a &amp;lt;&amp;lt; &quot; = &quot; &amp;lt;&amp;lt; a &amp;lt;&amp;lt; endl
#define foreach(it, l) for ( typeof(l.begin()) it = l.begin(); it != l.end(); it++) 
#define dbl(i, a) cout &amp;lt;&amp;lt; &quot;[&quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &quot;]&quot; &amp;lt;&amp;lt; &quot; = &quot;&amp;lt;&amp;lt; a &amp;lt;&amp;lt; &quot;, &quot;; 
#define listar(lista) for(int i = 0; i &amp;lt; lista.size(); i++) { dbl(i, lista[i]);} cout &amp;lt;&amp;lt; endl;
using namespace std;
int main() {
 /*freopen(&quot;perm.in&quot;, &quot;r&quot;, stdin);
 freopen(&quot;perm.out&quot;, &quot;w&quot;, stdout);*/
 #ifdef dennisbot
  freopen(&quot;in.in&quot;, &quot;r&quot;, stdin);
 #endif 
 int n;
 while (scanf(&quot;%d&quot;, &amp;n) != EOF) {
  if (n == 0) {
   break;
  }
  string num = &quot;&quot;;
  for (int i = 0; i &amp;lt; 32; i++) {
   if (n &gt;&gt; i &amp; 1) {
    num += &quot;1&quot;;
   }
   else num += &quot;0&quot;;
  }
  num = num.substr(0, num.find_last_of(&quot;1&quot;) + 1);
  int t = 1, res = 0;
  for (int i = num.size() - 1; i &gt;= 0; i--) {
   res += (num[i] - 48) * t;
   t *= 2;
  }
  printf(&quot;%d\n&quot;, res);
 }
 return 0;
}

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingproblemsolutions.blogspot.com/feeds/1828927717752606839/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/03/2841-bitwise-reverse-tju.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1828927717752606839'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9147331577528336601/posts/default/1828927717752606839'/><link rel='alternate' type='text/html' href='http://programmingproblemsolutions.blogspot.com/2012/03/2841-bitwise-reverse-tju.html' title='2841.   Bitwise Reverse, tju'/><author><name>dennisbot</name><uri>http://www.blogger.com/profile/17853598198795228042</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>