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 :)
Showing posts with label Ad hoc. Show all posts
Showing posts with label Ad hoc. Show all posts

Wednesday, January 7, 2015

UVA 455 - Periodic Strings

/*
Problem link
Type: string process, kmp, adhoc
Algorithm:

Wednesday, January 15, 2014

Uva 256 - Quirksome Squares

 1  /*
 2  Problem link
 3  Type: Complete Search
 4  Algorithm:
 5      Just do as it says
 6  */

Monday, June 17, 2013

Tuesday, May 28, 2013

Wednesday, March 27, 2013

Wednesday, January 30, 2013

Wednesday, January 23, 2013

Thursday, January 17, 2013

uva 299 - Train Swapping


 1  /*
 2  Problem link
 3  Type: Ad hoc, Sorting.
 4  Algorithm: Insertion Sort.
 5  */

Saturday, December 15, 2012

uva 10954 - Add All



/*
Problem link
Type: Adhoc - greedy, Data structure - priority queue
*/
 1  #include <iostream>
 2  #include <cstdio>
 3  #include <cstring>
 4  #include <cmath>
 5  #include <vector>
 6  #include <queue>

Friday, December 14, 2012

uva 11926 - Multitasking


/*
Problem link
Type: Adhoc, brute-force
*/
 1  #include <iostream>
 2  #include <cstdio>
 3  #include <cstring>
 4  #include <cmath>
 5  #include <cstdlib>
 6  #include <vector>
 7  using namespace std;
 8  const int maxn = 1000010;

Monday, December 3, 2012

uva 12015 - Google is Feeling Lucky


/*
Problem link
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int n = 20;

class url {
public:
 string link;
 int value;
};

url a[n];

int main() {
 int ntest;
 string line;
 cin >> ntest;
 for (int test=1; test<=ntest; test++)
 {
  printf("Case #%d:\n",test);
  for (int i=1; i<=10; i++) 
  {
   cin >> a[i].link;
   cin >> a[i].value;
  }
  int themax = 0;
  for (int i=1; i<=n; i++) themax = a[i].value>themax ? a[i].value : themax;
  for (int i =1; i<=n; i++)
   if (a[i].value==themax) cout << a[i].link << endl;
 } 
 return 0;
}

uva 11942 - Lumberjack Sequencing


/*
Problem link
*/
#include <iostream>
#include <cstdio>
using namespace std;
const int n = 10;

int a[n];

int main() {
 int ntest;
 cin >> ntest;
 cout << "Lumberjacks:" << endl;
 for (int test=1; test<=ntest; test++)
 {
  for (int i=1; i<=n; i++) cin >> a[i];
  int tmp = a[2]-a[1];
  int i;
  for (i=3; i<=n; i++)
   if ((a[i]-a[i-1])*tmp<=0)
   {
    cout << "Unordered" << endl;
    break;
   }
  if (i==n+1) cout << "Ordered" << endl;
 }
 return 0;
}

Monday, November 26, 2012

uva 11799 - Horror Dash


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

int main() {
 int ntest, n;
 cin >> ntest;
 for (int test=1; test<=ntest; test++)
 {
  cin >> n;
  int max = 0, value;
  for (int i=1; i<=n; i++) 
  {
   cin >> value;
   if (value>max) max = value;
  }
  printf("Case %d: %d\n",test, max);
 }
}