This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code Jam Individual Problem - Equal Sum - Carolina Garma | |
// Prev knowledge: binary representation, partitions | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace GoogleJam | |
{ | |
class EqualSum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kotlin solution | |
fun powers_of_two(N:Int):MutableList<Long> { | |
/* | |
This function generates a tactical N set of numbers made of powers of 2 | |
and the remaining N-30 numbers will be the last N numbers before 10**9 inclusive. | |
As N is always 100, this fuction is always performed without problems | |
*/ | |
var A = mutableListOf<Long>() // Open empty list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Solution | |
def powers_of_two(N): | |
""" | |
This function generates my proposed tactical N sets of numbers made of powers of 2 | |
and the remaining N-30 numbers will be the last N numbers before 10**9 inclusive. | |
As N is always 100, this fuction is always performed without problems | |
""" | |
A = [2**i for i in range(30)] + [10**9 - n for n in range(N-30)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Main function in C# | |
static void Main(string[] args) | |
{ | |
long T = Convert.ToInt64(Console.ReadLine()); // Read # of Cases | |
for (int i = 0; i < T; i++){ | |
int N = Convert.ToInt32(Console.ReadLine()); // Read N | |
if (N == -1) { // if N==-1, end program | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Powers of two in C# | |
static List<long> powers_of_two(int N) | |
/* | |
This function generates my proposed tactical N sets of numbers made of powers of 2 | |
and the remaining N-30 numbers will be the last N numbers before 10**9 inclusive. | |
As N is always 100, this fuction is always performed without problems | |
*/ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Solve sum in C# | |
static List<long> solve_sum(List<long> A, List<long> B) | |
/* | |
This function implements a greedy approach to minimize the sum difference | |
among two sets A and B | |
*/ | |
{ | |
// Join A and B into a new list C | |
var C = new List<long>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top left print | |
String top_left_plus = ".."; | |
for (int i = 0; i < cols - 1 ; i ++) { | |
top_left_plus += "+-"; | |
} | |
top_left_plus += "+"; | |
print(top_left_plus); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Constructing the string to print multiple times | |
String plus = ""; | |
String bars = ""; | |
// Plus sign string | |
for (int i = 0; i < cols ; i ++) { | |
plus += "+-"; | |
} | |
plus += "+"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solveTree(): | |
N = int(input()) # Number of nodes/modules/leaves | |
F = [0] + [int(f) for f in str(input()).split(' ')] # List of fun factors + an extra 0 at the begining to store the abyss (root value) | |
P = [int(p) for p in str(input()).split(' ')] # List of pointers | |
adj = [[] for i in range(N+1)] # Create an array of adjacency lists of all the nodes + 1 list for the abyss adj nodes | |
for i in range(len(P)): # For each pointer | |
# Add the adj nodes to the node pointed | |
adj[P[i]].append(i+1) # append the index + 1 as we added the abyss as a node,so adj[0] are the nodes pointing to the abyss then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Solve sum in Kotlin | |
fun solve_sum(A:MutableList<Long>, B:MutableList<Long>):MutableList<Long> { | |
/* | |
This function implements a greedy approach to minimize the sum difference | |
among two sets A and B | |
*/ | |
var C = A + B | |
C = C.sortedDescending().toMutableList() |
OlderNewer