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

Commit 11829c9

Browse files
authored
Merge pull request #2 from javaarchive/pc1
Add files via upload
2 parents 589a38a + d6e6ae2 commit 11829c9

File tree

1 file changed

+69
-10
lines changed

1 file changed

+69
-10
lines changed

usacotools.java

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public abstract class usacotools {
1515
public static ArrayList<Exception> console=new ArrayList<Exception>();
1616
public static String error="Error";
1717
public static int debugcode=-1;
18+
public static boolean DEBUG=false;
1819
public static boolean isrect(int[][] map,int x,int y) {
1920
int cachedsize=-1;
2021
int cachey=-1;
@@ -135,6 +136,24 @@ public static int binarySearch(int arr[], int l, int r, int x)
135136

136137
return -1;
137138
}
139+
public static int[][] copy2D(int[][] a){
140+
int[][] b=new int[a.length][];
141+
for(int i=0;i<a.length;i++) {
142+
b[i]=new int[a[i].length];
143+
for(int j=0;j<a[i].length;j++) {
144+
b[i][j]=a[i][j];
145+
}
146+
}
147+
return b;
148+
}
149+
public static int[] copyarr(int[] a) {
150+
int[] b=new int[a.length];
151+
152+
for(int i=0;i<a.length;i++) {
153+
b[i]=a[i];
154+
}
155+
return b;
156+
}
138157
public static int ebs(int arr[], int l, int r, int x) {
139158
Arrays.sort(arr);
140159
return binarySearch(arr, l, r, x);
@@ -256,7 +275,7 @@ public static int[][] rotate90cw(int[][] map) {
256275
* 90 degree clockwise
257276
*/
258277
int N=map.length;
259-
int[][] n=new int[N][N];
278+
int[][] n=new int[map[0].length][N];
260279
for(int i=0;i<N;i++) {
261280
for(int j=0;j<N;j++) {
262281
n[j][N-1-i]=map[i][j];
@@ -327,6 +346,26 @@ public static void show2Darr(int[][] a) {
327346
public static void showarr(int[] a) {
328347
for(int x:a) {print(x+" ");}
329348
}
349+
public static int[][] dpcache;
350+
public static int ks(int W,int[] wt,int[] val,int n) {
351+
int result;
352+
if(dpcache[n][W]!=0) {return dpcache[n][W];}
353+
if(n==0||W==0) {
354+
result=0;
355+
}else if(wt[n-1]>W) {
356+
result=ks(W,wt,val,n-1);
357+
358+
359+
360+
}else {
361+
result=Math.max(val[n-1]+ks(W-wt[n-1],wt,val,n-1),ks(W,wt,val,n-1));
362+
}
363+
dpcache[n][W]=result;
364+
return result;
365+
}
366+
public static void kssetup(int n,int W) {
367+
dpcache=new int[n+1][W+1];
368+
}
330369
public static void main(String[] args) throws Exception{
331370
/*
332371
* Short demo of stuff
@@ -339,26 +378,46 @@ public static void main(String[] args) throws Exception{
339378
print("Welcome to the demo");
340379
print(">","");
341380
int val;
381+
/*
342382
int[][] testarray= {
343-
{1,1,1,1,1,1,1,1},
344-
{1,1,1,0,0,1,1,2},
345-
{0,0,0,0,0,0,0,0},
346-
{0,0,0,0,0,0,0,0},
347-
{0,0,0,0,0,0,0,0},
348-
{1,1,1,1,1,1,1,1},
349-
{1,1,1,1,1,1,1,1},
383+
{1,1,2,7,7,1,1,1},
384+
{1,1,4,0,7,1,2,2},
385+
{0,3,6,9,1,0,0,0},
386+
{0,3,0,1,0,0,0,0},
387+
{0,3,0,0,0,0,0,0},
388+
{1,1,5,1,3,1,1,1},
389+
{1,1,1,1,3,1,1,1},
350390
};
351-
print("Roation of 90 degrees\n Before \n\n\n\n");
391+
*/
392+
int[][] testarray= {
393+
{1,2,3,1},
394+
{4,5,6,2},
395+
{7,8,9,3},
396+
{10,69,1,4}
397+
398+
};
399+
print("Roation of 90 degrees\n Before \n ");
352400
show2Darr(testarray);
353401
print("After \n");
354402
show2Darr(rotate90cw(testarray));
403+
print("BEFORE:");
404+
int[][] ii= {
405+
{1,1,2,3},
406+
{1,0,2,1},
407+
{1,1,1,1},
408+
{1,2,3,4}
409+
};
410+
show2Darr(ii);
411+
print("After H reflect:");
412+
show2Darr(reverseh(ii));
413+
355414
try {
356415
val=sc.nextInt();
357416
}catch(Exception e) {
358417
print("Oops that did not go well please rerun and choose a INTEGER");
359418
val=-1;
360419
report(e);
361-
print("How about we test erro reporting");
420+
print("How about we test error reporting");
362421
console();
363422
}
364423
if(1==val) {

0 commit comments

Comments
 (0)