// Topcoder Single Round Match 591 Round 1 - Division II, Level One
using System;
using System.Collections.Generic;
using System.Linq;
public class TheArithmeticProgression
{
public double minimumChange ( int a, int b, int c )
{
double bb = ( a + c ) / 2.0;
double aa = 2 * b - c;
double cc = 2 * b - a;
double ans = double.MaxValue;
double r = Math.Abs ( bb - b );
ans = Math.Min ( ans, r );
r = Math.Abs ( aa - a );
ans = Math.Min ( ans, r );
r = Math.Abs ( cc - c );
ans = Math.Min ( ans, r );
return ans;
}
static void Main ( string[] args ) { }
}
Some solution examples of problems in topcoder, codeeval, google code jam, interviewstreet, onlinejudge-uva, codeforces, projecteuler, etc
Sunday, December 14, 2014
Topcoder Single Round Match 590 Round 1 - Division II, Level One
// Topcoder Single Round Match 590 Round 1 - Division II, Level One
using System;
using System.Collections.Generic;
using System.Linq;
public class FoxAndGomoku
{
public String win ( String[] board )
{
int cx = board[0].Length;
int cy = board.Length;
for ( int y = 0; y < cy; y++ )
{
for ( int x = 0; x < cx; x++ )
{
int cnt1=0;
int cnt2=0;
int cnt3=0;
int cnt4=0;
for ( int i = 0; i < 5; i++ )
{
if ( ( y + i ) >= 0 && ( y + i ) < cy )
if ( board[y + i][x] == 'o' )
cnt1++;
if ( ( x + i ) >= 0 && ( x + i ) < cx )
if ( board[y][x + i] == 'o' )
cnt2++;
if ( ( ( x + i ) >= 0 && ( x + i ) < cx ) && ( ( y
+ i ) >= 0 && ( y + i ) < cy ) )
if ( board[y + i][x + i] == 'o' )
cnt3++;
if ( ( ( x - i ) >= 0 && ( x - i ) < cx ) && ( ( y
+ i ) >= 0 && ( y + i ) < cy ) )
if ( board[y + i][x - i] == 'o' )
cnt4++;
}
if ( cnt1 >= 5 || cnt2 >= 5 || cnt3 >= 5 || cnt4 >= 5 )
return "found";
}
}
return "not found";
}
static void Main ( string[] args ) { }
}
using System;
using System.Collections.Generic;
using System.Linq;
public class FoxAndGomoku
{
public String win ( String[] board )
{
int cx = board[0].Length;
int cy = board.Length;
for ( int y = 0; y < cy; y++ )
{
for ( int x = 0; x < cx; x++ )
{
int cnt1=0;
int cnt2=0;
int cnt3=0;
int cnt4=0;
for ( int i = 0; i < 5; i++ )
{
if ( ( y + i ) >= 0 && ( y + i ) < cy )
if ( board[y + i][x] == 'o' )
cnt1++;
if ( ( x + i ) >= 0 && ( x + i ) < cx )
if ( board[y][x + i] == 'o' )
cnt2++;
if ( ( ( x + i ) >= 0 && ( x + i ) < cx ) && ( ( y
+ i ) >= 0 && ( y + i ) < cy ) )
if ( board[y + i][x + i] == 'o' )
cnt3++;
if ( ( ( x - i ) >= 0 && ( x - i ) < cx ) && ( ( y
+ i ) >= 0 && ( y + i ) < cy ) )
if ( board[y + i][x - i] == 'o' )
cnt4++;
}
if ( cnt1 >= 5 || cnt2 >= 5 || cnt3 >= 5 || cnt4 >= 5 )
return "found";
}
}
return "not found";
}
static void Main ( string[] args ) { }
}
Subscribe to:
Posts (Atom)