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

Commit f77a330

Browse files
committed
Work on gold problem, edit old problem
1 parent 4c3f86d commit f77a330

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

src/convention.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.io.*;
2+
import java.util.*;
3+
public class convention {
4+
static int[] time = new int[100000];static int N,M,C;
5+
public static boolean pos(int waittime) {
6+
int w = 1;
7+
int fa = time[0];
8+
int firstpos = 0;// Default
9+
10+
for(int i = 1; i < N;i++) {
11+
if(time[i] - fa > waittime || (i + 1 - firstpos > C)){
12+
w += 1;
13+
fa = time[i];
14+
firstpos = i;
15+
}
16+
}
17+
return (w <= M);
18+
}
19+
static int bs(int low,int high)
20+
{
21+
if(low == high) return low;
22+
if(low + 1 == high)
23+
{
24+
if(pos(low)) return low;
25+
return high;
26+
}
27+
int mid = (low+high)/2;
28+
if(pos(mid)) return bs(low,mid);
29+
else return bs(mid+1,high);
30+
}
31+
// Power counter 123456789
32+
static int MAX_POSSIBLE = 1000000000;
33+
public static void main(String[] args) throws IOException{
34+
BufferedReader f = new BufferedReader(new FileReader("convention.in"));
35+
// TODO Auto-generated method stub
36+
StringTokenizer st = new StringTokenizer(f.readLine());
37+
N = Integer.parseInt(st.nextToken());
38+
M = Integer.parseInt(st.nextToken());
39+
C = Integer.parseInt(st.nextToken());
40+
st = new StringTokenizer(f.readLine());
41+
for(int i = 0; i < N; i++) {
42+
time[i] = Integer.parseInt(st.nextToken());
43+
}
44+
f.close();
45+
PrintWriter pw = new PrintWriter(new FileWriter("convention.out"));
46+
pw.print(bs(0,MAX_POSSIBLE));
47+
pw.close();
48+
}
49+
50+
}

src/dining.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import java.util.*;
2+
import java.io.*;
3+
public class dining {
4+
static final int V=9;
5+
int minDistance(int dist[], Boolean sptSet[])
6+
{
7+
8+
int min = Integer.MAX_VALUE, min_index=-1;
9+
10+
for (int v = 0; v < V; v++)
11+
if (sptSet[v] == false && dist[v] <= min)
12+
{
13+
min = dist[v];
14+
min_index = v;
15+
}
16+
17+
return min_index;
18+
}
19+
void printSolution(int dist[], int n)
20+
{
21+
System.out.println("Vertex Distance from Source");
22+
for (int i = 0; i < V; i++)
23+
System.out.println(i+" tt "+dist[i]);
24+
}
25+
26+
void dijkstra(int graph[][], int src)
27+
{
28+
int dist[] = new int[V];
29+
30+
Boolean sptSet[] = new Boolean[V];
31+
for (int i = 0; i < V; i++)
32+
{
33+
dist[i] = Integer.MAX_VALUE;
34+
sptSet[i] = false;
35+
}
36+
37+
38+
dist[src] = 0;
39+
for (int count = 0; count < V-1; count++)
40+
{
41+
42+
int u = minDistance(dist, sptSet);
43+
44+
45+
sptSet[u] = true;
46+
47+
48+
for (int v = 0; v < V; v++)
49+
50+
51+
52+
if (!sptSet[v] && graph[u][v]!=0 &&
53+
dist[u] != Integer.MAX_VALUE &&
54+
dist[u]+graph[u][v] < dist[v])
55+
dist[v] = dist[u] + graph[u][v];
56+
}
57+
58+
59+
printSolution(dist, V);
60+
}
61+
public static void main(String[] args) {
62+
BufferedReader f = new BufferedReader();
63+
64+
}
65+
66+
}

0 commit comments

Comments
 (0)