0 0 投票数

## 硬币

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
if (m < n) {
System.out.println(1);
} else {
int ans = 0;
int x = n;
while (m != 0) {
int num = m / x;
ans += num;
m = m - num * x;
while (x > m)
x--;
}

System.out.println(ans);
}
in.close();
}

}

## 奇妙的数列

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int l = in.nextInt() - 1;
int r = in.nextInt();
int L = (l % 2 == 0 ? 1 : -1) * ((l + 1) / 2);
int R = (r % 2 == 0 ? 1 : -1) * ((r + 1) / 2);
System.out.println(R - L);
}
in.close();
}

}

## 石头剪刀布

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int s = in.nextInt();
final int p = (int) (1e9 + 7);
if (s > n)
System.out.println(0);
else
System.out.println(lucas(n, s, p) * powMod(2, n - s, p) % p);
in.close();
}

static long powMod(long n, long k, long p) {
long ans = 1;
while (k != 0) {
if (k % 2 == 1)
ans = (ans * n) % p;
n = (n * n) % p;
k >>= 1;
}
return ans;
}

static long C(long n, long m, long p) {
if (m == 0)
return 1;
if (m > n - m)
m = n - m;
long up = 1, down = 1;
for (int i = 1; i <= m; i++) {
up = (up * (n - i + 1)) % p;
down = (down * i) % p;
}
return up * powMod(down, p - 2, p) % p;
}

static long lucas(long n, long m, long p) {
if (m == 0)
return 1;
return C(n % p, m % p, p) * lucas(n / p, m / p, p);
}

}

## 气球游戏

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[] q = new int[n];
int[] count = new int[m + 1];
for (int i = 0; i < n; i++) {
q[i] = in.nextInt();
}
int l = 0;
int r = m - 1;
for (int i = l; i <= r; i++) {
count[q[i]]++;
}
int min = 0;
while (!all(count, m)) {
r++;
if (r == n) {
min = -1;
break;
}
count[q[r]]++;
}
if (min != -1) {
min = r - l + 1;
}
while (min != -1) {
while (count[q[l]] > 1) {
count[q[l]]--;
l++;
}
min = Math.min(min, r - l + 1);
r++;
if (r == n)
break;
count[q[r]]++;
}

System.out.println(min);
in.close();
}

private static boolean all(int[] count, int m) {
for (int i = 1; i <= m; i++) {
if (count[i] == 0) {
return false;
}
}
return true;
}

}

0 0 投票数