Showing posts with label problem-3. Show all posts
Showing posts with label problem-3. Show all posts

Friday, May 23, 2014

March 2014 Silver Problem 3: Mooo Moo

Result: incomplete

I gave up, and the partial code in this file is pointless.

mooomoo.cpp

Friday, February 14, 2014

February 2014 Bronze Problem 3: Secret Code

Result: 10/10 **********

This one took more time than Problem 1 and Problem 2, but at least I actually finished this Problem 3, unlike the last few ones.

scode.cpp

Tuesday, December 17, 2013

December 2013 Bronze Problem 3: Wormholes

Result: incomplete

It's too difficult, but I had it partially done. Other partial work is in the recycling by now.

wormhole.cpp

Tuesday, November 19, 2013

November 2013 Bronze Problem 3: Farmer John has no Large Brown Cow

Result: 3/10 **ssx*ssss

I somehow ran out of memory and the permutations were not correct in one case.

nocow.cpp

Tuesday, February 12, 2013

February 2013 Bronze Problem 3: Perimeter

Result: 1/10 *xxxxxxxxx

I found out that this solution is flawed because it doesn't "fill the holes" correctly. It fails when there are two adjacent hole cells.

perimeter.cpp

Tuesday, December 18, 2012

December 2012 Bronze Problem 3: Crazy Fences

Result: 0/10 xsxssssssx (why were there signals?)

I have given up on this one. As a result, I just submitted code that will return C, in hopes that no boxes are formed by the fences for as many test cases as possible.

Wednesday, November 21, 2012

November 2012 Bronze Problem 3: Horseshoes

Result: 8/10 **x***x*** (2 wrong answers)

hshoe.cpp
#include <iostream>
#include <fstream>
#include <string>

#define loopi(x) loopi_start(x,0)
#define loopi_start(x,s) for(int i = (s); i < (x); ++i)
#define loop_rev(a,x,stop) for(int a = (x); a >= (stop); --a)

using namespace std;

int N, first_max;

int maxlen(string str, int pos, int first = 0, int second = 0, bool starting = true){
 if(starting && str[pos] != ')'){
  if(str[pos] == '('){
   if(++first > N * N / 2) return 0; // too long
  }
  else return 0; // fail (already there)
 }
 else{
  if(str[pos] != ')') return 0; // fail
  if(++second >= first) return first + second; // completed path
  starting = false;
 }
 // keep going
 str[pos] = ' ';
 int best = 0;
 // left
 if(pos % N) best = max(best, maxlen(str, pos - 1, first, second, starting));
 // right
 if(pos % N < N - 1 && pos < N * N - 1) best = max(best, maxlen(str, pos + 1, first, second, starting));
 // up
 if(pos >= N) best = max(best, maxlen(str, pos - N, first, second, starting));
 // down
 if(pos < N * (N - 1) - 1) best = max(best, maxlen(str, pos + N, first, second, starting));
 return best;
}

int main() {
 ofstream fout ("hshoe.out");
 ifstream fin("hshoe.in");
 // get input
 fin >> N;
 first_max = N * N / 2; // and it is truncated down anyways
 string str;
 loopi(N){
  string tmp;
  fin >> tmp;
  str += tmp;
 }
 // process
 int max_length = maxlen(str, 0);
 // output
 fout << max_length << '\n';
 // cleanup
 fin.close();
 fout.close();
 return 0;
}