Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.cefaloschoolproject.commands;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- static class Transaction {
- private int id;
- private long size;
- private double fee;
- public Transaction(int id, long size, double fee) {
- this.id = id;
- this.size = size;
- this.fee = fee;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public long getSize() {
- return size;
- }
- public void setSize(long size) {
- this.size = size;
- }
- public double getFee() {
- return fee;
- }
- public void setFee(double fee) {
- this.fee = fee;
- }
- }
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- List<Transaction> transactions = new ArrayList<>();
- int toalNumberOfTransactions = 12;
- for(int i =0;i<toalNumberOfTransactions;i++){
- String line = sc.nextLine();
- String[] tokens = line.split(" ");
- int id = Integer.parseInt(tokens[0]);
- long byteSize = Long.parseLong(tokens[1]);
- double fee = Double.parseDouble(tokens[2]);
- transactions.add(new Transaction(id,byteSize,fee));
- }
- int resultSet = 0;
- long maxBytes = 1000000;
- double result = 0;
- double eps = 1e-15;
- double defaultReward = 12.5;
- for(int mask=0;mask<(1<<toalNumberOfTransactions);mask++){
- long byteForCurrentSet = 0;
- double currentScore = 0;
- for(int j=0;j<toalNumberOfTransactions;j++)
- {
- Transaction t = transactions.get(j);
- if((mask&(1<<j))!=0){
- byteForCurrentSet+=t.getSize();
- currentScore+=t.getFee();
- }
- }
- if(byteForCurrentSet<=maxBytes && result+eps<currentScore){
- result = currentScore;
- resultSet = mask;
- }
- }
- System.out.println("Current Score = " + (result+defaultReward ) + "BTC");
- long sizeTaken = 0;
- for(int i=0;i<toalNumberOfTransactions;i++)
- {
- if((resultSet&(1<<i))!=0){
- Transaction t = transactions.get(i);
- sizeTaken+=t.getSize();
- System.out.println(String.format("Id = %d Size = %d Fee = %f",t.getId(),t.getSize(),t.getFee()));
- }
- }
- System.out.println(String.format("Size taken = %d",sizeTaken));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment