GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/convention.java at master · javaarchive/Java
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
Expand file tree/ Copy pathconvention.javaMore file actions 91 lines (87 loc) · 2.34 KB / Copy pathconvention.javaFile metadata and controls91 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 import java.io.*; import java.util.*; public class convention { public static boolean check(int test,int M, int C, List<Integer> buses) { int busStart=buses.get(0); int busCount = 1; int cowCount = 0; for(int i = 0; i < buses.size(); i ++) { if(busCount > M) { return false; } int time = buses.get(i); if(time - busStart > test || cowCount == C) { busCount ++; busStart = time; cowCount = 0; } cowCount++; } return true; } public static void endProgram(int answer) throws IOException{ PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("convention.out"))); pw.println(answer); pw.close(); System.exit(0); } public static void main(String[] args) throws IOException{ BufferedReader f = new BufferedReader(new FileReader("convention1.in")); StringTokenizer st = new StringTokenizer(f.readLine()); int N,M,C; N = Integer.parseInt(st.nextToken()); M = Integer.parseInt(st.nextToken()); C = Integer.parseInt(st.nextToken()); st = new StringTokenizer(f.readLine()); f.close(); System.out.println(N+" "+M+" "+C); List<Integer> arrivTime = new ArrayList<>(); for(int i = 0; i < N; i ++) { arrivTime.add(Integer.parseInt(st.nextToken())); } arrivTime.sort(null); // 123456789 int max = 1000000000; int min = 0; while(true) { int mid = (int) Math.floor((min + max)/2); if(check(mid,M,C,arrivTime)) { max = mid; }else { min = mid; } System.out.println(min+" "+mid+" "+max); } } } class Cow implements Comparator<Cow>{ int id; int aTime; public Cow(int id, int aTime) { this.id = id; this.aTime = aTime; } @Override public int compare(Cow arg0, Cow arg1) { // TODO Auto-generated method stub return Integer.compare(arg0.aTime, arg1.aTime); } } class PriorityElem implements Comparator<PriorityElem>, Comparable<PriorityElem>{ public int multiplier = 1; public int priority; public int item; public PriorityElem(int item, int priority) { this.item = item; this.priority = priority; } @Override public int compare(PriorityElem arg0, PriorityElem arg1) { // TODO Auto-generated method stub return Integer.compare(arg0.priority, arg1.priority); } @Override public int compareTo(PriorityElem arg0) { return this.compare(this, arg0); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |