文章目录
这个呢 会更新的超级超级慢 也不一定能补完 但会慢慢补 慢慢更
A. JB Loves Math
给定两个数 a、b。求出让a变成b的最少次数。
能修改a的值为 加上一个奇数 和 减去一个偶数
直接判断 a 和 b 的关系
设: x为奇数, y为偶数
a == b 直接输出0
a > b 这就一定需要减一个偶数
我们看 a 和 b 之间的差值
如果差值为偶数 那么直接减一个偶数即可 也就是
a
−
y
a - y
a−y
如果差值为奇数 那么需要减一个偶数,然后加一个奇数,也就是
a
−
y
+
x
a - y + x
a−y+x 即可
a < b
我们还是看 a 和 b 之间的差值
如果差值为奇数,那么直接加一个奇数即可,也就是 a + x
如果差值为偶数,那么需要考虑:差值是
奇数
∗
2
奇数*2
奇数∗2呢 还是
偶数
∗
2
偶数*2
偶数∗2。 如果是
奇数
∗
2
奇数*2
奇数∗2,那么
a
+
x
+
x
a + x + x
a+x+x就可以了 。但是如果是
偶数
∗
2
偶数*2
偶数∗2 的话 那么就是
a
+
x
+
x
−
y
a + x + x - y
a+x+x−y 才行
可以看看 a = 1, b = 11 和 a = 1, b = 13 这两个例子
最后的最后 就是直接判断即可
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int t = sc.nextInt();
while (t-- > 0)
{
int a = sc.nextInt(), b = sc.nextInt();
if (a == b)
out.println(0);
else if (a > b)
out.println((a - b) % 2 == 0 ? 1 : 2);
else
{
if ((b - a) % 2 == 1)
out.println(1);
else
out.println((b - a) / 2 % 2 == 0 ? 3 : 2);
}
}
out.flush();
out.close();
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
}
B. JB Loves Comma
将给定字符串中的"cjb" 变成 “cjb,”
直接替换输出即可
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
String s = sc.next();
out.println(s.replace("cjb", "cjb,"));
out.flush();
out.close();
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
}
C. JB Wants to Earn Big Money
给定 n个想买入的股票价格 和 m 个想出售的股票价格 以及最终价x
求出有多少可以加入交易的人
可以加入交易的
· 买入的价格 不小于 最终价
· 出售的价格 不高于 最终价
直接判断即可
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n = sc.nextInt(), m = sc.nextInt(), x = sc.nextInt();
int ans = 0;
for (int i = 1; i <= n; i++)
{
int a = sc.nextInt();
if (a >= x)
ans++;
}
for (int i = 1; i <= m; i++)
{
int b = sc.nextInt();
if (b <= x)
ans++;
}
out.println(ans);
out.flush();
out.close();
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
}
D. The Profiteer
E. Easy Jump
F. Easy Fix
G. Easy Glide
H. A=B
I. Barbecue
J. Frog
K. Dynamic Reachability
L. Candy Machine
M. BpbBppbpBB