1.java 语言使用的字符码集是(D)
A.ASCII
B.BCD
C.DCB
D.Unicode
2.不要二
https://www.nowcoder.com/questionTerminal/1183548cd48446b38da501e58d5944eb
二货小易有一个W*H的网格盒子,网格的行编号为0H-1,网格的列编号为0W-1。每个格子至多可以放一块蛋糕,任意两块蛋糕的欧几里得距离不能等于2。
对于两个格子坐标(x1,y1),(x2,y2)的欧几里得距离为:
( (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) ) 的算术平方根
小易想知道最多可以放多少块蛋糕在网格盒子里。
//** ** **
//** ** **
// ** ** **
// ** ** **
//** ** **
//** ** **
//只要数清楚,每个4行中,
//i或i+1行的蛋糕数为 (n / 4) * 2 + (n % 4 < 2 ? n % 4 : 2)
//i+2或i+3行的蛋糕数为 ((n - 2) / 4) * 2 + ((n - 2) % 4 < 2 ? (n - 2) % 4 : 2)
//然后算清楚一共有多少个完整的4行就行, 当然是共有m / 4 个。
//唯一要注意的就是处理行数除4有余数的情况,把最后可能剩余的1~3 行加进去。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt(), n = sc.nextInt();
int evenICount = (n / 4) * 2 + (n % 4 < 2 ? n % 4 : 2);
int oddICount = ((n - 2) / 4) * 2 + ((n - 2) % 4 < 2 ? (n - 2) % 4 : 2);
int ans = m / 4 * (evenICount + oddICount) * 2;
if (m % 4 > 0) ans += evenICount;
if (m % 4 > 1) ans += evenICount;
if (m % 4 > 2) ans += oddICount;
System.out.println(ans);
}
}
3.求最小公倍数
public class Test8 {
private static int Solution(int a,int b){
int min = Math.min(a,b);
int max = Math.max(a,b);
int index = (max/min)+1;
for(int i = 2;i<9;i++){
if(min%i==0&&max%i==0){
while ((min*index)%max!=0){
index++;
}
return min*index;
}
}
if(max%min==0){
return max;
}
return max*min;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int result = Solution(a,b);
System.out.println(result);
}
}
//方法二
//于两个数的乘积等于这两个数的最大公约数与最小公倍数的积
//求最大公约数:
//1. a/b,令r为所得余数(0≤r<b) 若r=0,算法结束,a即为答案
//2. 互换:置 a←b,b←r,并返回第一步
public class Main {
public static int lcm(int m, int n) {
return (m * n) / gcd(m, n);
}
private static int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
System.out.println(lcm(a, b));
}
}
4.证明一个数是否为斐波那契数
public class Test10 {
private static int Fab(int n){
if(n==1||n==2){
return 1;
}
return Fab(n-1)+Fab(n-2);
}
private static boolean fab(int num){
int index = 1;
while (Fab(index)<num){
index++;
}
if(Fab(index)==num){
return true;
}else {
return false;
}
}
public static void main(String[] args) {
System.out.println(fab(13));
}
}