Introduction

This is my blog of programming, I take notes and leave codes of computer science problems I solved here. Be my guest to comment :)

Wednesday, October 31, 2012

uva 314 - Robot


/*Problem link
  BFS, Graph.
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
const int maxn = 60;
const int dx[12]={0,0,0,-1,-2,-3,0,0,0,1,2,3};
const int dy[12]={-1,-2,-3,0,0,0,1,2,3,0,0,0};
const int oo = 20000000;

Monday, October 29, 2012

uva 11332 - Summing Digits


Problem link
#include <iostream>
#include <cstdio>
using namespace std;

int g(int x) {
 if (x/10==0) return(x);
 int sum=0;
 while (x>0)
 {
  sum+=(x%10);
  x/=10;
 }
 return(g(sum));
}

int main() {
 int n;
 cin >> n;
 while (n)
 {
  cout << g(n) << endl;
  cin >> n;
 }
 return 0;
}

uva 11172 - Relational Operator


Problem link
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
 int nTest;
 cin >> nTest;
 for (int test=1; test<=nTest; test++)
 {
  int a,b;
  cin >> a >> b;
  if (a<b) cout << "<" << endl;
  else if (a>b) cout << ">" << endl;
  else cout << "=" << endl;
 }
 return 0;
}

Sunday, October 28, 2012

uva 679 - Dropping Balls


Problem link
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
const int maxn = 1048577;

uva 957 - Popes


Problem link
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
const int maxp=100010;

uva 11044 - Searching for Nessy


Problem link

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main() {
 int ntest;
 cin >> ntest;
 for (int test=1; test<=ntest; test++)
 {
  int n,m;
  cin >> n >> m;
  n-=2; m-=2;
  int col=m/3;
  if (m%3!=0) col++;
  int row=n/3;
  if (n%3!=0) row++;
  cout << (long long)col*row << endl;  
 }
 return 0;
}

Friday, October 26, 2012

Codeforces round #147 div 2 - Problem C


/*
This program solve Problem C codeforces round #147 div 2
Date: 26/10/2012
  -------------------------------
*/
#include <iostream>
#include <cstdio>
#include <cstring>

Tuesday, October 23, 2012

uva 10550 - Combination Lock



Problem link
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
 int a,b,c,d;
 cin >> a >> b >> c >> d;
 while (a!=0 || b!=0 || c!=0 || d!=0)
 {
  int g1,g2,g3;
  if (b>a) g1 = 40-b+a; else g1 = a-b;
  if (c>b) g2 = c-b; else g2=40-b+c;
  if (d>c) g3 = 40+c-d; else g3 = c-d;
  int result = 360*2 + g1*9 + 360 + g2*9 + g3*9;
  cout << result << endl;
  cin >> a >> b >> c >> d;
 }
 return 0;
}


Monday, October 22, 2012

uva 394 - Mapmaker

Problem link
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 10010;
//-----------------------------
class arr {
public:
    string name;
    int address;
    int size;
    int D;
    int u[21],l[21];
};    

Sunday, October 21, 2012

uva 10420 - List of Conquests


Problem link
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 2010;
//---------------------------------
class person {public: string pos; int value;};
//---------------------------------
int n;
person list[maxn];

Friday, October 19, 2012

UVA 259 - Software Allocation


This problem uses the max flow algorithm by Edmonds Karp
Problem link
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = 40;
const int oo=1000;
//----------------------------------
int res[maxn][maxn],p[maxn];
int mf,f,s,t,n,sum;