Professional Documents
Culture Documents
import java.util.*;
import java.util.Scanner;
class Main {
j[i] = scn.next().charAt(0);
p[i] = scn.nextInt();
d[i] = scn.nextInt();
System.out.print("\n--------------\n");
max = d[0];
for (int i = 1; i < job_count; i++) {
max = d[i];
seq[i] = '0';
int n = d.length;
p[k + 1] = temp1;
d[k + 1] = temp2;
j[k + 1] = temp3;
}
int m;
int profit = 0;
//
m = d[i];
while (m > 0) {
if (seq[m - 1] == '0') {
seq[m - 1] = j[i];
break;
} else {
m--;
System.out.println("Sequence is ");
if (seq[i] != '0') {
System.out.print(seq[i]);
DIJKSTRA
import java.util.*;
{
public static void main(String[] args)
{ 2, 0, 1, 0, 0, 0, 1 }, { 0, 0, 3, 0, 0, 2, 0 }, { 0, 3, 0, 0, 2, 0, 1 }, { 0, 0, 0, 1, 0, 1, 0 }};
int count=graph.length;
int source=sc.nextInt();
// make all distance from source to all other node infinite at the beginning
for(int i=0;i<count;i++)
distance[i]=Integer.MAX_VALUE;
visited[i]=false;
distance[source]=0;
for(int i=0;i<count;i++)
int res=-1;
int min=Integer.MAX_VALUE;
for(int j=0;j<count;j++)
min=distance[j];
res=j;
}
visited[res]=true;
for(int k=0;k<count;k++)
distance[k]=distance[res]+graph[res][k];
FLOYD WARSHALL
import java.util.*;
class Main {
int n = 4;
A[i][j] = scn.nextInt();
System.out.println();
System.out.println();
int min;
int p = 1;
int path_sum = 0;
if (A[i][1] == 0) {
min = A[i][2];
} else {
min = A[i][1];
min = A[i][j];
p = j;
0 3 100 7
8 0 2 100
5 100 0 1
2 100 100 0
Knights TOUR
class Main {
static int N = 8;
System.out.println();
sol[x][y] = -1;
sol[0][0] = 0;
return false;
} else
printSolution(sol);
return true;
int yMove[]) {
if (movei == N * N)
return true;
next_x = x + xMove[k];
next_y = y + yMove[k];
sol[next_x][next_y] = movei;
return true;
else
sol[next_x][next_y] = -1;
return false;
STUDENTS CLUB
import java.util.*;
int n = sc.nextInt();
System.out.println();
cost[i][j] = sc.nextInt();
vis[i] = -1;
if (vis[i] == -1) {
if (i == j)
continue;
if (vis[j] != -1) {
sum += cost[vis[j]][j];
} else {
mini = cost[k][j];
sum += mini;
lb = sum;
club = i;
vis_count++;
if (vis_count == n)
ans = lb;
vis[club] = vis_count;
SQUARE OF NUMBER
import java.util.*;
public class Square
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number: ");
long num = sc.nextLong();
long ans = squareofnum(num);
System.out.println("Square is " + ans);
}
public static long squareofnum(long num){
if(num < 10){
return num * num;
}
long temp = num;
long count = 0;
while(temp > 0){
count ++;
temp /= 10;
}
long half = count / 2;
long a = num / (long)Math.pow(10, half); //left part of number
long b = num % (long)Math.pow(10, half); //right part of number
long ll = squareofnum(a);
long rr = squareofnum(b);
long lr_rl = squareofnum(a + b) - ll - rr;