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

Commit 8057f57

Browse files
committed
Removed my test line
1 parent 16d4991 commit 8057f57

2 files changed

Lines changed: 120 additions & 120 deletions

File tree

convention2.in

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
5
2-
25 3
3-
105 30
4-
20 50
5-
10 17
6-
100 10
7-
Line not scanned
1+
5
2+
25 3
3+
105 30
4+
20 50
5+
10 17
6+
100 10

src/convention2.java

Lines changed: 114 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,115 @@
1-
import java.io.*;
2-
import java.util.*;
3-
public class convention2 {
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-
if(theline.isEmpty()) {
36-
tc = time.get(i);// Short for the cow
37-
}else {
38-
System.out.println(tc.x +" " + tc.y +" "+ theline.get(0).x+" "+theline.get(0).y);
39-
c2 = theline.get(0);
40-
boolean nodouble = c2.equals(tc);
41-
if(nodouble) {
42-
i --; // Make sure loop runs again
43-
time.remove(c2); // Remove cow
44-
tc = theline.remove(0); // Let the waiting cow eat
45-
continue;
46-
}
47-
48-
ctime = tc.x + tc.y - c2.x;
49-
System.out.println("Achieved time of "+ctime);
50-
if(ctime > mtime) {
51-
if(!nodouble) {
52-
System.out.println("New range");
53-
mtime = ctime;
54-
}
55-
}
56-
i --; // Make sure loop runs again
57-
time.remove(c2); // Remove cow
58-
//senority.remove(theline.get(0));
59-
tc = theline.remove(0); // Let the waiting cow eat
60-
tc.x = tc.x + ctime;
61-
}
62-
63-
c1 = tc.x + tc.y;
64-
for(int j = i + 1; j < time.size(); j ++) {
65-
if (time.get(i).x > time.get(j).x) {
66-
//break;
67-
continue; // On second thought
68-
//throw new IOException("Something impossible just happeneded.");
69-
}
70-
if(time.get(j).x > c1) {
71-
break;
72-
}
73-
74-
theline.add(time.get(j));
75-
theline.sort(cowcompare);
76-
}
77-
if(i == 0 && first) {
78-
//System.out.println(theline.remove(0));
79-
}
80-
System.out.println(theline);
81-
first = false;
82-
}
83-
//System.out.println(mtime);
84-
PrintWriter pw = new PrintWriter(new FileWriter("convention2.out"));
85-
pw.print(mtime);
86-
pw.close();
87-
}
88-
89-
90-
}
91-
class cow implements Comparable<cow>{
92-
int x,y;
93-
public cow(int i,int j) {
94-
this.x = i;
95-
this.y = j;
96-
}
97-
@Override
98-
public int compareTo(cow arg0) {
99-
// TODO Auto-generated method stub
100-
return this.x - arg0.x;
101-
}
102-
@Override
103-
public String toString() {
104-
return "("+this.x+","+this.y+")";
105-
}
106-
@Override
107-
public boolean equals(Object k) {
108-
if(!(k instanceof cow)) {
109-
return false;
110-
}
111-
cow c = (cow) k;
112-
return (c.x == this.x) && (c.y == this.y);
113-
}
1+
import java.io.*;
2+
import java.util.*;
3+
public class convention2 {
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+
if(theline.isEmpty()) {
36+
tc = time.get(i);// Short for the cow
37+
}else {
38+
System.out.println(tc.x +" " + tc.y +" "+ theline.get(0).x+" "+theline.get(0).y);
39+
c2 = theline.get(0);
40+
boolean nodouble = c2.equals(tc);
41+
if(nodouble) {
42+
i --; // Make sure loop runs again
43+
time.remove(c2); // Remove cow
44+
tc = theline.remove(0); // Let the waiting cow eat
45+
continue;
46+
}
47+
48+
ctime = tc.x + tc.y - c2.x;
49+
System.out.println("Achieved time of "+ctime);
50+
if(ctime > mtime) {
51+
if(!nodouble) {
52+
System.out.println("New range");
53+
mtime = ctime;
54+
}
55+
}
56+
i --; // Make sure loop runs again
57+
time.remove(c2); // Remove cow
58+
//senority.remove(theline.get(0));
59+
tc = theline.remove(0); // Let the waiting cow eat
60+
tc.x = tc.x + ctime;
61+
}
62+
63+
c1 = tc.x + tc.y;
64+
65+
for(int j = i + 1; j < time.size(); j ++) {
66+
if (time.get(i).x > time.get(j).x) {
67+
//break;
68+
continue; // On second thought
69+
//throw new IOException("Something impossible just happeneded.");
70+
}
71+
if(time.get(j).x > c1) {
72+
break;
73+
}
74+
75+
theline.add(time.get(j));
76+
theline.sort(cowcompare);
77+
}
78+
if(i == 0 && first) {
79+
//System.out.println(theline.remove(0));
80+
}
81+
System.out.println(theline);
82+
first = false;
83+
}
84+
//System.out.println(mtime);
85+
PrintWriter pw = new PrintWriter(new FileWriter("convention2.out"));
86+
pw.print(mtime);
87+
pw.close();
88+
}
89+
90+
91+
}
92+
class cow implements Comparable<cow>{
93+
int x,y;
94+
public cow(int i,int j) {
95+
this.x = i;
96+
this.y = j;
97+
}
98+
@Override
99+
public int compareTo(cow arg0) {
100+
// TODO Auto-generated method stub
101+
return this.x - arg0.x;
102+
}
103+
@Override
104+
public String toString() {
105+
return "("+this.x+","+this.y+")";
106+
}
107+
@Override
108+
public boolean equals(Object k) {
109+
if(!(k instanceof cow)) {
110+
return false;
111+
}
112+
cow c = (cow) k;
113+
return (c.x == this.x) && (c.y == this.y);
114+
}
114115
}

0 commit comments

Comments
 (0)