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

Commit 69f3073

Browse files
authored
Add files via upload
1 parent d1ed7a1 commit 69f3073

File tree

10 files changed

+281
-0
lines changed

10 files changed

+281
-0
lines changed

Training/friday.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

Training/friday.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
36 33 34 33 35 35 34

Training/milk1.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
10
2+
2 3
3+
4 5
4+
6 7
5+
8 9
6+
10 11
7+
12 13
8+
14 15
9+
16 17
10+
18 19
11+
1 20

Training/milk2.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
300 1000
3+
700 1200
4+
1500 2100

Training/milk2.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1500 1600

Training/milkerror.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
100 102
3+
64100 64102
4+
128100 128102

Training/milkio.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
6
2+
100 200
3+
200 400
4+
400 800
5+
800 1600
6+
50 100
7+
1700 3200

Training/notes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
September april june novemeber 30

cowroute.java

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.util.*;
4+
/*
5+
*
6+
*
7+
* Improvement for cowroute
8+
*/
9+
public class cowroute {
10+
11+
12+
public static void main(String[] args) throws IOException {
13+
StringTokenizer st;
14+
BufferedReader f= new BufferedReader(new FileReader("6.in"));
15+
st=new StringTokenizer(f.readLine());
16+
17+
int[] route= {0,0,0};
18+
ArrayList<int[]> aroutes=new ArrayList<int[]>();
19+
ArrayList<int[]> broutes=new ArrayList<int[]>();
20+
int A=Integer.parseInt(st.nextToken());
21+
int B=Integer.parseInt(st.nextToken());
22+
int N=Integer.parseInt(st.nextToken());
23+
/*
24+
* A routes and B routes item structure
25+
* First item-price
26+
* 1-Index
27+
* 2-Which route
28+
*/
29+
30+
boolean Before;
31+
boolean after;
32+
@SuppressWarnings("unchecked")
33+
ArrayList<Integer>[] data=new ArrayList[N];
34+
int price;
35+
int M,id;
36+
for(int i=0;i<N;i++) {
37+
data[i]=new ArrayList<Integer>();
38+
st=new StringTokenizer(f.readLine());
39+
price=Integer.parseInt(st.nextToken());
40+
M=Integer.parseInt(st.nextToken());
41+
st=new StringTokenizer(f.readLine());
42+
for(int j=0;j<M;j++) {
43+
id=Integer.parseInt(st.nextToken());
44+
if(id==A) {
45+
route[0]=j;
46+
route[1]=i;
47+
route[2]=price;
48+
aroutes.add(route.clone());
49+
}else if(id==B) {
50+
route[0]=j;
51+
route[1]=i;
52+
route[2]=price;
53+
broutes.add(route.clone());
54+
}
55+
data[i].add(id);
56+
}
57+
data[i].add(0, price);
58+
}
59+
//System.out.println("Finished first loop Debug status A:"+A+" B:"+B+" N:"+N);
60+
int low=-1;
61+
boolean k=true;
62+
int r,x;
63+
int price2=0,index,index2,count;
64+
ArrayList<Integer> a,b;
65+
a=new ArrayList<Integer>();b=new ArrayList<Integer>();
66+
//System.out.println("====Entering main loop===");
67+
68+
for(int[] stuff:aroutes) {
69+
a.clear();
70+
71+
price=stuff[2];//Get price
72+
index=stuff[0];
73+
r=stuff[1];
74+
count=0;
75+
after=false;
76+
for(int i:data[r]) {//For every item in the A route
77+
78+
if(i==A) {
79+
after=true;
80+
continue;
81+
}else if(i==B) {// If B is also in the route and we are past "A"
82+
if((price)<low||k) {
83+
k=false;
84+
//System.out.println("New low cost by all in one");
85+
System.out.println("Debug Info index:"+index+"- count:"+count);
86+
low=price;
87+
}
88+
89+
}
90+
count++;
91+
92+
if(after) {a.add(i);}
93+
}
94+
for(int[] dat:broutes) {
95+
96+
b.clear();
97+
98+
price2=dat[2];//Get price
99+
index2=dat[0];
100+
//r2=stuff[1];
101+
Before=true;
102+
for(int m=0;m<data[r].size();m++) {
103+
x=data[r].get(m);
104+
if(x==B) {
105+
Before=false;
106+
continue;
107+
}
108+
if(Before) {
109+
110+
111+
b.add(x);
112+
}
113+
}
114+
a.sort(null);
115+
b.sort(null);
116+
for(int i=0;i<a.size();i++) {
117+
System.out.println("Info I:"+i);
118+
count=a.get(i);
119+
120+
if(Arrays.binarySearch(b.toArray(),(a.get(i)))>-1) {//Flight overlap
121+
if(((price2+price)<low||low==-1)) {
122+
System.out.println("Debug for new overlap: The same value is:"+a.get(i)+" The first price is price:"+price+" and price2:"+price2);
123+
System.out.println("Debug count:"+count+" index2:"+index2);
124+
System.out.println("New low cost by overlap");
125+
low=price2+price;
126+
}
127+
}
128+
}
129+
}
130+
131+
132+
133+
134+
}
135+
PrintWriter pw=new PrintWriter(new FileWriter("cowroute.out"));
136+
pw.println(low);
137+
pw.close();
138+
f.close();
139+
140+
141+
}
142+
143+
}

moocast.java

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import java.io.*;
2+
import java.util.*;
3+
public class moocast {
4+
5+
private static int[][] data;
6+
private static int[][] map;
7+
private static int cowstargeted;
8+
private static int[][] modifmap;
9+
private static int cownum;
10+
public static void d(String a) {
11+
System.out.println(a);
12+
}
13+
public static void Cast(int cow) {
14+
d("Loading data varibles");
15+
16+
int range=data[cow][2];
17+
int x=data[cow][0];
18+
int y=data[cow][1];
19+
int a,b;
20+
d("Done");
21+
//int count=0;
22+
double calc=0;
23+
for(int x1=x-range;x1<x+range;x1++) {
24+
//count++;
25+
if(cownum==0) {break;}
26+
for(int y1=y-range;y1<y+range;y1++) {
27+
if(cownum==0) {break;}
28+
a=Math.max(x1-x, x-x1);
29+
b=Math.max(y1-y, y-y1);
30+
calc=Math.sqrt(a*a+b*b);
31+
32+
if(-1<x1&&-1<y1&&y1<25000&&x1<25000&&modifmap[x1][y1]!=0&&-1<calc&&calc<range+1) {
33+
34+
//count++;
35+
////////////System.out.println("X Y = "+x1+" - "+y1+" "+count);
36+
if(modifmap[x1][y1]>0) {
37+
cownum--;
38+
System.out.println("Cow found");
39+
////////////System.out.println("RAnge:"+range);
40+
////////////System.out.println(calc);
41+
////////////System.out.println("We've hit a cow");
42+
cowstargeted++;
43+
modifmap[x1][y1]=0;//Eliminate the cow
44+
//Above disables a cow
45+
Cast(map[x1][y1]);
46+
}
47+
48+
49+
50+
}
51+
}
52+
if(cownum==0) {break;}
53+
}
54+
}
55+
public static void main(String[] args) throws IOException {
56+
57+
d("Reading");
58+
BufferedReader f = new BufferedReader(new FileReader("3.in"));
59+
int N=Integer.parseInt(f.readLine());//Read N
60+
d("Parsed N");
61+
data = new int[N][3];
62+
StringTokenizer st;
63+
map = new int[25000][25000];
64+
d("Data init done");
65+
cownum = N;
66+
for(int i=0;i<N;i++) {
67+
cownum=N;
68+
/*Data Format
69+
* 0 x
70+
* 1 y
71+
* 2 Power
72+
*/
73+
st=new StringTokenizer(f.readLine());
74+
for(int j=0;j<3;j++) {
75+
data[i][j]=Integer.parseInt(st.nextToken());
76+
}
77+
map[data[i][0]][data[i][1]]=i+1;
78+
79+
}
80+
modifmap = map.clone();
81+
f.close();
82+
int high=1;
83+
for(int i=0;i<N;i++) {
84+
modifmap=map.clone();
85+
cowstargeted=1;
86+
////////////System.out.println("--Cow--");
87+
Cast(i);
88+
if(cowstargeted>high) {
89+
System.out.println("New high");
90+
high=cowstargeted;
91+
}
92+
}
93+
////////////System.err.println(high);
94+
f.close();
95+
d("Closed f now writting output");
96+
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("moocast.out")));
97+
98+
99+
pw.println(high);
100+
pw.flush();
101+
102+
pw.close();
103+
104+
105+
106+
}
107+
108+
}

0 commit comments

Comments
 (0)