Skip to content

Instantly share code, notes, and snippets.

@tivrfoa
tivrfoa / BatchSystem.java
Last active November 9, 2020 13:25
Solution for problem BatchSystem, used in Single Round Match 481 Round 1 - Division II, Level Three
package topcoder;
import java.util.*;
/**
* Problem statement:
* http://community.topcoder.com/stat?c=problem_statement&pm=10808&rd=14234
*
* I used permutation code from:
* http://www.cs.utexas.edu/users/djimenez/utsa/cs3343/lecture25.html
public class LevenshteinDistance
{
public static void main(String[] args)
{
new LevenshteinDistance().solve();
}
public void solve()
{
System.out.println(distance("exponential", "polynomial")); // 6
/*************************************************************************
* Compilation: javac LCS
* Execution: java LCS < example10.txt
* Dependencies: StdIn.java
*
* Reads in two strings from stdin and computes their longest
* common subsequence.
*
*************************************************************************/
@tivrfoa
tivrfoa / memset-matrix-test.cpp
Created May 17, 2013 17:43
Memset matrix test. memset when using the size of the matrix, change the values in all dimensions.
#include <stdio.h> // for printf
#include <cstring> // for memset
int main(int argc, char *argv[])
{
int xx[2][2] = {{1,1},{2,2}};
printf("{{%d,%d},{%d,%d}}\n", xx[0][0], xx[0][1], xx[1][0], xx[1][1]);
memset(xx, 0, sizeof(xx)); // change to {{0,0},{0,0}}
printf("{{%d,%d},{%d,%d}}\n", xx[0][0], xx[0][1], xx[1][0], xx[1][1]);
/*************************************************************************
* Compilation: javac Knapsack.java
* Execution: java Knapsack N W
*
* Generates an instance of the 0/1 knapsack problem with N items
* and maximum weight W and solves it in time and space proportional
* to N * W using dynamic programming.
*
* For testing, the inputs are generated at random with weights between 0
* and W, and profits between 0 and 1000.
@tivrfoa
tivrfoa / FordFulkerson.java
Created May 25, 2013 12:53
Source: http://algs4.cs.princeton.edu/64maxflow/FordFulkerson.java.html Copyright © 2002–2010, Robert Sedgewick and Kevin Wayne.
/*************************************************************************
* Compilation: javac FordFulkerson.java
* Execution: java FordFulkerson V E
* Dependencies: FlowNetwork.java FlowEdge.java Queue.java
*
* Ford-Fulkerson algorithm for computing a max flow and
* a min cut using shortest augmenthing path rule.
*
*********************************************************************/
@tivrfoa
tivrfoa / Knapsack1.java
Created June 21, 2013 23:31
Code made after watching class Knapsack 1 - problem formulation, dynamic programming (34:20) Course: Discrete Optimization from amazing professor Pascal Van Hentenryck
import java.util.Arrays;
public class Knapsack1
{
private int n; // number of itens
private int k; // capacity
private int[][] dp;
private Item[] itens;
private class Item implements Comparable<Item> {
@tivrfoa
tivrfoa / setCustomValidity.html
Created June 22, 2019 14:38
It enables change validation error message on an invalid input.
<!-- https://www.w3.org/TR/html50/forms.html#dom-cva-setcustomvalidity -->
<html>
<script>
function check(input, size) {
if (input.value.length < size) {
input.setCustomValidity('Favor preencher no mínimo ' +
size + ' caracteres.');
} else {
input.setCustomValidity('');
@tivrfoa
tivrfoa / material-icons.html
Created June 23, 2019 03:11
Easy light way to show nice icons on your web page
<!--
get the images base64 from the site below:
https://material.io/tools/icons/?style=baseline
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Material Icons</title>
<meta name="Description" content="material icons">
@tivrfoa
tivrfoa / change-css-variable.html
Created July 8, 2019 01:28
Changing css variable and animating
<html>
<style>
:root {
--padding-left: 3px;
--padding-top: 30px;
}
#box1 {
padding-left: var(--padding-left);