This file contains hidden or 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
A thief finds much more loot than his bag can fit. | |
Help him to find the most valuable combination of items assuming that | |
any fraction of a loot item can be put into his bag. | |
Task. The goal of this code problem is to implement an algorithm for the fractional knapsack problem. | |
Input Format. The first line of the input contains the number n of items and the capacity W of a knapsack. | |
The next n lines define the values and weights of the items. The i-th line contain integers v and w — | |
the value and the weight of i-th item, respectively. | |
Constraints. 1 ≤ n ≤ 10^3 | |
0 ≤ W ≤ 2 · 10^6 |
This file contains hidden or 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
public class Combinations { | |
public static void main(String[] args) { | |
List<String> data = new ArrayList<>(); | |
data.add("a"); | |
data.add("b"); | |
data.add("c"); | |
data.add("d"); | |
List<String> result = getCombinations(data); | |
for (String string : result) { |
This file contains hidden or 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
import java.util.Scanner; | |
/** | |
* Created by root on 11.08.16. | |
*/ | |
public class GreedyCoins { | |
public static void main(String[] args) { | |
Scanner scaner = new Scanner(System.in); | |
int m = scaner.nextInt(); | |
if (m < 1 || m > Math.pow(10, 3)) { |
This file contains hidden or 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
import java.util.Scanner; | |
/** | |
* Created by root on 11.08.16. | |
*/ | |
public class GreedyCoins { | |
public static void main(String[] args) { | |
Scanner scaner = new Scanner(System.in); | |
int m = scaner.nextInt(); | |
if (m < 1 || m > Math.pow(10, 3)) { |
This file contains hidden or 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
public class LCM { | |
public static void main(String[] args) { | |
Scanner scaner = new Scanner(System.in); | |
int first = scaner.nextInt(); | |
int second = scaner.nextInt(); | |
int gcd = getGCD(first, second); | |
long lcm = getLCM(first, second, gcd); | |
System.out.println(lcm); | |
} |
This file contains hidden or 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
public class LCM { | |
public static void main(String[] args) { | |
Scanner scaner = new Scanner(System.in); | |
int first = scaner.nextInt(); | |
int second = scaner.nextInt(); | |
int gcd = getGCD(first, second); | |
long lcm = getLCM(first, second, gcd); | |
System.out.println(lcm); | |
} |
This file contains hidden or 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
import java.util.Scanner; | |
/** | |
* Created by root on 10.08.16. | |
*/ | |
public class GCD { | |
public static void main(String[] args) { | |
Scanner scaner = new Scanner(System.in); | |
int first = scaner.nextInt(); | |
int second = scaner.nextInt(); |
This file contains hidden or 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
*/ | |
public class FibLast { | |
public static void main(String[] args) { | |
Scanner scaner = new Scanner(System.in); | |
int n = scaner.nextInt(); | |
System.out.println("Last digit for " + n + " = " + getFibonacci(n)); | |
} | |
private static int getFibonacci(int n) { | |
int[] fib = new int[n+1]; |
This file contains hidden or 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
import java.util.Scanner; | |
public class Fib { | |
public static void main(String[] args) { | |
Scanner scaner = new Scanner(System.in); | |
int n = scaner.nextInt(); | |
if (n <= 80) { | |
System.out.println("Fibonacci number for " + n + " = " + getFibonacci(n)); | |
} else { | |
System.out.println("To big input"); |
This file contains hidden or 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
int number = 101; | |
int lastDigit = number % 10; |