Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 464bfcb

Browse files
committed
Delete some code...............
1 parent f095e67 commit 464bfcb

File tree

2 files changed

+136
-48
lines changed

2 files changed

+136
-48
lines changed

convention2_timeout.java

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import java.io.*;
2+
import java.util.*;
3+
public class convention2_timeout {
4+
5+
public static void main(String[] args) throws IOException{
6+
BufferedReader f= new BufferedReader(new FileReader("convention2.in"));
7+
StringTokenizer st;
8+
int N = Integer.parseInt(f.readLine());
9+
Map<cow,Integer> senority = new HashMap<cow,Integer>();
10+
ArrayList<cow> time = new ArrayList<cow>();
11+
for(int i = 0; i < N ; i ++) {
12+
st = new StringTokenizer(f.readLine());
13+
cow thecow = new cow(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()));
14+
senority.put(thecow,i);
15+
time.add(thecow);
16+
thecow = null;
17+
}
18+
19+
Collections.sort(time); // Looks a bit more stylish
20+
//time.sort(null);
21+
Comparator<cow> cowcompare = new Comparator<cow>() {
22+
@Override
23+
public int compare(cow arg0, cow arg1) {
24+
// TODO Auto-generated method stub
25+
return senority.get(arg0) - senority.get(arg1);
26+
}
27+
};
28+
List<cow> theline = new ArrayList<cow>();
29+
int c1; // Cache calculations
30+
cow tc = new cow(-2,-2);
31+
int mtime = -1,ctime;
32+
cow c2;
33+
boolean first =true;
34+
for(int i = 0; i < time.size(); i ++) {
35+
System.out.println("Completed "+i+" of "+time.size()+" <- Value may change but N is "+N);
36+
if(theline.isEmpty()) {
37+
tc = time.get(i);// Short for the cow
38+
}else {
39+
//System.out.println(tc.x +" " + tc.y +" "+ theline.get(0).x+" "+theline.get(0).y);
40+
c2 = theline.get(0);
41+
boolean nodouble = c2.equals(tc);
42+
if(nodouble) {
43+
i --; // Make sure loop runs again
44+
time.remove(c2); // Remove cow
45+
tc = theline.remove(0); // Let the waiting cow eat
46+
continue;
47+
}
48+
49+
ctime = tc.x + tc.y - c2.x;
50+
//System.out.println("Achieved time of "+ctime);
51+
if(ctime > mtime) {
52+
if(!nodouble) {
53+
//System.out.println("New range");
54+
mtime = ctime;
55+
}
56+
}
57+
i --; // Make sure loop runs again
58+
time.remove(c2); // Remove cow
59+
//senority.remove(theline.get(0));
60+
tc = theline.remove(0); // Let the waiting cow eat
61+
tc.x = tc.x + ctime;
62+
}
63+
64+
c1 = tc.x + tc.y;
65+
66+
for(int j = i + 1; j < time.size(); j ++) {
67+
if (time.get(i).x > time.get(j).x) {
68+
//break;
69+
continue; // On second thought
70+
//throw new IOException("Something impossible just happeneded.");
71+
}
72+
if(time.get(j).x > c1) {
73+
break;
74+
}
75+
76+
theline.add(time.get(j));
77+
theline.sort(cowcompare);
78+
}
79+
if(i == 0 && first) {
80+
//System.out.println(theline.remove(0));
81+
}
82+
System.out.println(theline);
83+
first = false;
84+
}
85+
//System.out.println(mtime);
86+
PrintWriter pw = new PrintWriter(new FileWriter("convention2.out"));
87+
pw.print(mtime);
88+
pw.close();
89+
}
90+
91+
92+
}
93+
class cow implements Comparable<cow>{
94+
int x,y;
95+
public cow(int i,int j) {
96+
this.x = i;
97+
this.y = j;
98+
}
99+
@Override
100+
public int compareTo(cow arg0) {
101+
// TODO Auto-generated method stub
102+
return this.x - arg0.x;
103+
}
104+
@Override
105+
public String toString() {
106+
return "("+this.x+","+this.y+")";
107+
}
108+
@Override
109+
public boolean equals(Object k) {
110+
if(!(k instanceof cow)) {
111+
return false;
112+
}
113+
cow c = (cow) k;
114+
return (c.x == this.x) && (c.y == this.y);
115+
}
116+
}

src/convention2.java

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,58 +30,30 @@ public int compare(cow arg0, cow arg1) {
3030
cow tc = new cow(-2,-2);
3131
int mtime = -1,ctime;
3232
cow c2;
33-
boolean first =true;
34-
for(int i = 0; i < time.size(); i ++) {
35-
System.out.println("Completed "+i+" of "+time.size()+" <- Value may change but N is "+N);
36-
if(theline.isEmpty()) {
37-
tc = time.get(i);// Short for the cow
38-
}else {
39-
//System.out.println(tc.x +" " + tc.y +" "+ theline.get(0).x+" "+theline.get(0).y);
40-
c2 = theline.get(0);
41-
boolean nodouble = c2.equals(tc);
42-
if(nodouble) {
43-
i --; // Make sure loop runs again
44-
time.remove(c2); // Remove cow
45-
tc = theline.remove(0); // Let the waiting cow eat
46-
continue;
47-
}
48-
49-
ctime = tc.x + tc.y - c2.x;
50-
//System.out.println("Achieved time of "+ctime);
51-
if(ctime > mtime) {
52-
if(!nodouble) {
53-
//System.out.println("New range");
54-
mtime = ctime;
55-
}
56-
}
57-
i --; // Make sure loop runs again
58-
time.remove(c2); // Remove cow
59-
//senority.remove(theline.get(0));
60-
tc = theline.remove(0); // Let the waiting cow eat
61-
tc.x = tc.x + ctime;
62-
}
63-
64-
c1 = tc.x + tc.y;
65-
66-
for(int j = i + 1; j < time.size(); j ++) {
67-
if (time.get(i).x > time.get(j).x) {
68-
//break;
69-
continue; // On second thought
70-
//throw new IOException("Something impossible just happeneded.");
71-
}
72-
if(time.get(j).x > c1) {
33+
int cows_eaten = 0;
34+
int maxsenority;
35+
System.out.println(time);
36+
while(cows_eaten < N) {
37+
tc = time.get(cows_eaten);
38+
maxsenority = -1;
39+
cow nextcow = new cow(-1,-1); // Not guarented to have a conflicting time
40+
int j = 0;
41+
while(true) {
42+
j ++;
43+
if(time.get(cows_eaten + j).x >= tc.x+tc.y || theline.contains(time.get(cows_eaten + j))) { // If after the current cow is finsihed then all cows after it we don't have to worry about
7344
break;
45+
}else {
46+
int current_senority = senority.get(time.get(cows_eaten + j));
47+
if(current_senority > maxsenority) {
48+
maxsenority = current_senority;
49+
nextcow = time.get(cows_eaten + j);
50+
}
7451
}
75-
76-
theline.add(time.get(j));
77-
theline.sort(cowcompare);
78-
}
79-
if(i == 0 && first) {
80-
//System.out.println(theline.remove(0));
8152
}
82-
//System.out.println(theline);
83-
first = false;
53+
if(nextcow.x != -1 && nextcow.y != -1) {theline.add(nextcow);}
8454
}
55+
56+
8557
//System.out.println(mtime);
8658
PrintWriter pw = new PrintWriter(new FileWriter("convention2.out"));
8759
pw.print(mtime);

0 commit comments

Comments
 (0)