Skip to content

Instantly share code, notes, and snippets.

View shixiaoyu's full-sized avatar
🤪
Why so Serious?

Xiaoyu shixiaoyu

🤪
Why so Serious?
View GitHub Profile
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int testCases = s.nextInt();
int caseNum = 1;
Plates plates = new Plates();
while (caseNum <= testCases) {
int n = s.nextInt();
int k = s.nextInt();
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int testCases = s.nextInt();
int caseNum = 1;
Training training = new Training();
while (caseNum <= testCases) {
int n = s.nextInt();
int p = s.nextInt();
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int testCases = s.nextInt();
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Stack;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int testCases = s.nextInt();
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int testCases = s.nextInt();
int caseNum = 1;
private class Node {
public int val;
public List<Node> neighbors;
public Node(int val) {
this.val = val;
this.neighbors = new ArrayList<>();
}
}
public boolean canFinishBfsTopoSort(int numCourses, int[][] prerequisites) {
if (numCourses <= 1 || prerequisites.length == 0 || prerequisites[0].length == 0) {
return true;
}
Map<Integer, Set<Integer>> graph = new HashMap<>();
// could be extracted into a build graph function
for (int i = 0; i < numCourses; i++) {
graph.put(i, new HashSet<>());
// This is a DFS solution, basically just like detecting if a graph has loops.
// Used a lookup table prune, with lookup, this is O(V + E), same as BFS since each node is visited once and only once
public boolean canFinish(int numCourses, int[][] prerequisites) {
if (numCourses <= 1 || prerequisites.length == 0 || prerequisites[0].length == 0) {
return true;
}
// this is adjacency list, used a set to dedup
Map<Integer, Set<Integer>> graph = new HashMap<>();
public class Block {
public int x;
public int y;
public Block(int x, int y) {
this.x = x;
this.y = y;
}
}
private final int[] xDirection = {1, 0, -1, 0};
private final int[] yDirection = {0, -1, 0, 1 };
public int numIslands(char[][] grid) {
if (grid == null || grid.length == 0 || grid[0].length == 0) {
return 0;
}
int m = grid.length;
int n = grid[0].length;