-
Notifications
You must be signed in to change notification settings - Fork 0
/
order_pricelist.java
111 lines (99 loc) · 2.33 KB
/
order_pricelist.java
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
import java.util.Scanner;
public class order_pricelist{
private bars B = new bars();
private Scanner scan = new Scanner(System.in);
//these objects are made in order to use constructors
class Order{
//it keeps data about order
private long sum;
//sum of lengths of ordered bars
private long[] tab;
//tab of lengths of bars
private String strategy;
//strategy of cutting bars
public Order(){
//constructors read input and sets all attributes
this.sum = 0;
int P = scan.nextInt();
this.tab = new long[P];
for(int i=0;i<P;i++){
tab[i] = scan.nextLong();
sum = sum + tab[i];
}
this.strategy = scan.next();
}
public String get_strategy(){
return this.strategy;
}
public void done(int i){
//if tab[i] = -1 it means that this section is already made
tab[i] = -1;
}
public long get_sum(){
return this.sum;
}
public long get_bar_length(int i){
return this.tab[i];
}
public int get_tab_length(){
return this.tab.length;
}
}
class PriceList{
//it keeps data about pricelist
private bars.Bar[] tab;
// tab of available bars, Bar keeps his length and price
private long max_price;
// max price of all available bars
public PriceList(){
//reads input and sets attributes
int C = scan.nextInt();
this.tab = new bars.Bar[C];
long max = 0;
for(int i=0;i<C;i++){
long l = scan.nextLong();
long p = scan.nextLong();
tab[i] = B.new Bar(l,p);
if(p > max){
max = p;
}
}
this.max_price = max;
}
public bars.Bar get_Bar(int i){
return this.tab[i];
}
public bars.Bar find_min(long l){
//looks for the smallest Bar in pricelist which size is bigger than l
int i = 0;
while(i < this.tab.length && l > this.tab[i].get_length()){
i++;
}
if(i == this.tab.length){
return null;
}
return this.tab[i];
}
public bars.Bar find_min_price(long l){
//looks for the cheapest Bar in pricelist which size is bigger than l
int index = -1;
long min = this.max_price;
for(int i=0;i<this.tab.length;i++){
if(this.tab[i].get_price() <= min && l <= this.tab[i].get_length()){
index = i;
min = this.tab[i].get_price();
}
}
if(index == -1){
return null;
}
return this.tab[index];
}
public long get_max(){
return this.max_price;
}
public int get_tab_length(){
return this.tab.length;
}
}
}