This repository was archived by the owner on Feb 29, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvention.java
More file actions
Latest commit
91 lines (87 loc) · 2.34 KB
/
Copy pathconvention.java
File metadata and controls
91 lines (87 loc) · 2.34 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
importjava.io.*;
importjava.util.*;
publicclassconvention {
publicstaticbooleancheck(inttest,intM, intC, List<Integer> buses) {
intbusStart=buses.get(0);
intbusCount = 1;
intcowCount = 0;
for(inti = 0; i < buses.size(); i ++) {
if(busCount > M) {
returnfalse;
}
inttime = buses.get(i);
if(time - busStart > test || cowCount == C) {
busCount ++;
busStart = time;
cowCount = 0;
}
cowCount++;
}
returntrue;
}
publicstaticvoidendProgram(intanswer) throwsIOException{
PrintWriterpw = newPrintWriter(newBufferedWriter(newFileWriter("convention.out")));
pw.println(answer);
pw.close();
System.exit(0);
}
publicstaticvoidmain(String[] args) throwsIOException{
BufferedReaderf = newBufferedReader(newFileReader("convention1.in"));
StringTokenizerst = newStringTokenizer(f.readLine());
intN,M,C;
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
st = newStringTokenizer(f.readLine());
f.close();
System.out.println(N+" "+M+" "+C);
List<Integer> arrivTime = newArrayList<>();
for(inti = 0; i < N; i ++) {
arrivTime.add(Integer.parseInt(st.nextToken()));
}
arrivTime.sort(null);
// 123456789
intmax = 1000000000;
intmin = 0;
while(true) {
intmid = (int) Math.floor((min + max)/2);
if(check(mid,M,C,arrivTime)) {
max = mid;
}else {
min = mid;
}
System.out.println(min+" "+mid+" "+max);
}
}
}
classCowimplementsComparator<Cow>{
intid;
intaTime;
publicCow(intid, intaTime) {
this.id = id;
this.aTime = aTime;
}
@Override
publicintcompare(Cowarg0, Cowarg1) {
// TODO Auto-generated method stub
returnInteger.compare(arg0.aTime, arg1.aTime);
}
}
classPriorityElemimplementsComparator<PriorityElem>, Comparable<PriorityElem>{
publicintmultiplier = 1;
publicintpriority;
publicintitem;
publicPriorityElem(intitem, intpriority) {
this.item = item;
this.priority = priority;
}
@Override
publicintcompare(PriorityElemarg0, PriorityElemarg1) {
// TODO Auto-generated method stub
returnInteger.compare(arg0.priority, arg1.priority);
}
@Override
publicintcompareTo(PriorityElemarg0) {
returnthis.compare(this, arg0);
}
}