# Aide-mémoire privé pour la programmation compétitive (Java)

Remarque. Ajouté séquentiellement.

## Arrondissez le reste

``````public static int roundUp(int a, int b) {
return (a + b - 1) / b;
}
``````

## Engagement maximum

Calculez en utilisant la méthode de division mutuelle euclidienne.

``````private static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
``````

Par exemple, si a = 370 b = 273

Loop a b
1 370 273
2 273 370 % 273 = 117
3 117 273 % 117 = 39
4 39 117 % 39 = 0

Lorsque b = 0, `return a` renvoie la valeur de a. Cette valeur est l'engagement maximum.

## Multiple commun minimum

Calculez en utilisant l'engagement maximum.

``````private static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
``````

## Matrice de rotation

``````double rad = Math.toRadians(60);
Point u = new Point(ux, uy);
``````

## Recherche de priorité de largeur

``````import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DFS {

private class Graph {
List<List<Integer>> graph;
boolean[] seen;

public Graph(int n) {
graph = new ArrayList<>();
seen = new boolean[n];
for (int i = 0; i < n; i++) {
seen[i] = false;
}
}

public void add(int from, int to) {
}

public void search(int v) {
seen[v] = true;

for (int next : graph.get(v)) {
if (seen[next]) continue;
search(next);
}
}
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

final int N = sc.nextInt();
final int M = sc.nextInt();

Graph graph = new DFS().new Graph(N);

for (int i = 0; i < M; i++) {
final int A = Integer.valueOf(sc.next());
final int B = Integer.valueOf(sc.next());