输入必须两个5+一个7
AC代码:
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solve Work = new Solve();
int T = 1;
// int T = Integer.parseInt(in.next());
for (int i = 1; i <= T; i++) {
Work.main(i, in, out);
}
out.close();
}
static class Solve {
public void main(int testNumber, InputReader in, PrintWriter out) {
int[] a = new int[3];
int cnt = 0, cnt1 = 0;
for (int i = 0; i < 3; i++) {
a[i] = in.nextInt();
if (a[i] == 5) {
cnt++;
}
if (a[i] == 7) {
cnt1++;
}
}
if (cnt == 2 && cnt1 == 1) {
out.println("YES");
} else {
out.println("NO");
}
}
}
//IO
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
Iroha Loves Strings (ABC Edition)
要求所有字符串拼接起来字典序最小,直接sort排序
AC代码:
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solve Work = new Solve();
int T = 1;
// int T = Integer.parseInt(in.next());
for (int i = 1; i <= T; i++) {
Work.main(i, in, out);
}
out.close();
}
static class Solve {
public void main(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(), l = in.nextInt();
String[] a = new String[n];
for (int i = 0; i < n; i++) {
a[i] = in.next();
}
Arrays.sort(a);
for (int i = 0; i < n; i++) {
out.print(a[i]);
}
}
}
//IO
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
金额不能出现给出的数字,暴力
AC代码:
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solve Work = new Solve();
int T = 1;
// int T = Integer.parseInt(in.next());
for (int i = 1; i <= T; i++) {
Work.main(i, in, out);
}
out.close();
}
static class Solve {
public void main(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(), k = in.nextInt();
int[] a = new int[k];
for (int i = 0; i < k; i++) {
a[i] = in.nextInt();
}
boolean ok = false;
int ans = n;
while (!ok) {
int z = ans;
boolean ok1 = true;
while (z > 0) {
int p = z % 10;
for (int i = 0; i < k; i++) {
if (a[i] == p) {
ok1 = false;
break;
}
}
z /= 10;
}
if (ok1) {
ok = true;
} else {
ans++;
}
}
out.println(ans);
}
}
//IO
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
比较有意思的组合数学问题,看到数据范围行和列都是最大1e5的范围,肯定不能dp从(1,1)到(n,m)记录方案数,所以考虑其他方法
由于只能往下走或者往右走,所以能走到(n,m)的位置只能在给出的矩形的右上方第一行,即给出的矩形和能走区域的缺口处,所以问题转化为从(1,1)走到缺口处的方案数*从缺口处到达(n,m)的方案数的和,由于从缺口处的上面一行走到缺口处方案数不改变,所以可以简化为矩形上方所有区域和矩形旁边所有区域
AC代码:
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solve Work = new Solve();
int T = 1;
// int T = Integer.parseInt(in.next());
for (int i = 1; i <= T; i++) {
Work.main(i, in, out);
}
out.close();
}
static final int mod = 1000000007;
static long[] fac, inv;
static class Solve {
public void main(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt(), m = in.nextInt(), a = in.nextInt(), b = in.nextInt();
fac = new long[200010];
inv = new long[200010];
init();
long ans = 0;
for (int i = b + 1; i <= m; i++) {
ans = (ans + (calc(1, 1, n - a, i) * calc(n - a + 1, i, n, m)) % mod) % mod;
}
out.println(ans);
}
public void init() {
fac[0] = 1;
for (int i = 1; i <= 200000; i++) {
fac[i] = fac[i - 1] * i % mod;
}
inv[200000] = qp(fac[200000], mod - 2);
for (int i = 200000 - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
public long qp(long a, long b) {
long res = 1;
for (; b > 0; b >>= 1, a = a * a % mod) {
if ((b & 1) == 1) {
res = res * a % mod;
}
}
return res;
}
public long calc(int x, int y, int xx, int yy) {
return C(xx - x + yy - y, xx - x);
}
public long C(int x, int y) {
if (y < 0 || y > x) {
return 0L;
}
return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
}
//IO
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}