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 in Kotlin | |
fun main() { | |
val T:Int = readln().toInt(); // Read number of cases | |
for (t in 0..T-1) { | |
var N:Int = readln().toInt(); // Read N int | |
if (N == -1) { | |
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
# Main in python | |
def main(): | |
T = int(input()) | |
for t in range(T): | |
N = int(input()) # Read N | |
if N==-1: | |
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
# Solve Sum in Python | |
def solve_sum(A, B): | |
""" | |
This function implements a greedy approach to minimize the sum difference | |
among two sets A and B | |
""" | |
C = sorted(A + B, reverse=True) # Join both subsets and sort them in reversed order | |
a_sum = 0 | |
b_sum = 0 |
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() |
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
// 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
// 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
// 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
// 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
// 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; | |
} |
NewerOlder