-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
115 lines (100 loc) · 2.84 KB
/
Solution.java
File metadata and controls
115 lines (100 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.util.Vector;
import java.util.HashMap;
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.*;
public class Solution{
public class Library
{
public int B,D,S; //books, days for sign up, ship limit
public Vector<Integer> books;
public Vector<Integer> score;
public Library(Scanner scanner, int d)
{
B = scanner.nextInt();
D = scanner.nextInt();
S = scanner.nextInt();
books = new Vector<Integer>(B);
for (int i = 0; i < B; ++i)
books.set(i, scanner.nextInt());
score = new Vector<Integer>(d);
}
public void calcScore(HashMap<Integer,Integer> bs)
{
//TAKE INTO CONSIDERATION THE DAYS
//sort books based off of score value
return;
}
public Integer getBook(int i ) //returns the ith best book
{
return books.get(i);
}
public Integer getScorewithDays(int d)
{
return score.get(d);
}
public Integer getBooksWithDays(int d)
{
if (d*S >= books.size())
return books.size();
else
return d*S;
}
}
public void calculateScore(Vector<Library> ls, HashMap<Integer,Integer> bs)
{
for (int i = 0; i < ls.size(); ++i)
(ls.get(i)).calcScore(bs);
}
public Vector<Integer> selectLibs(Vector<Library> ls)
{
return null;
}
public void solve()
{
}
public static void main(String args[]) throws IOException
{
Solution solution = new Solution();
//get file name
System.out.print("file: ");
Scanner scanner = new Scanner(System.in);
String fName = scanner.next();
File f = new File(fName + ".in");
scanner = new Scanner(f);
//input
Integer B, L, D; //books, libraries, days
B = scanner.nextInt();
L = scanner.nextInt();
D = scanner.nextInt();
//hashmap used to store a record of bookId to score mapping, this allows for O(1) access
HashMap<Integer,Integer> bs = new HashMap<Integer,Integer>(5*B); //reduces collision
for (int i = 0; i < B; ++i)
bs.put(i, scanner.nextInt());
Vector<Library> ls = new Vector<Library>(L);
for (int i = 0; i < L;++i)
{
Solution.Library x = solution.new Library(scanner, D);
ls.set(i, x);
}
//handle alg
//start by constructing a list of Library score given x days
//stored in l.d
solution.calculateScore(ls,bs);
//then select Libraries to maximize score
Vector<Integer> selectedLibs = solution.selectLibs(ls);
//output results
PrintWriter writer = new PrintWriter(fName + ".out");
writer.println(selectedLibs.size());
for (int i = 0; i < selectedLibs.size(); ++i)
{
D -= ls.get(selectedLibs.get(i)).D;
writer.print(selectedLibs.get(i)); writer.print(" "); writer.println( (ls.get(selectedLibs.get(i))).getBooksWithDays(D));
for (int j = 0; j < (ls.get(selectedLibs.get(i))).getBooksWithDays(D); ++j)
writer.println((ls.get(selectedLibs.get(i))).getBook(j) + " ");
writer.println("");
}
return;
}
}