来到学校后第一次参加算法比赛,听学长说去年的难度非常高,所以这次比赛目标就是得到分数。但今年的难度整体偏低,第八题做的比较懵,第十题不会做(连题都看不懂 ),其他的感觉做的还可以,对的起这段时间刷的算法题(在算法上花的时间比在小组布置的学习任务上花的时间多了近一倍,并且小组考核又是第一 ),唯一不爽的点可能就是用idea用习惯了,再用eclipse感觉非常不舒服。
2019的二进制数是多少,一道填空题。 这段时间重点没有放在数据结构上,通过不断的做题,对JAVA各种对象的方法用的非常熟悉。这一题对我而言也是非常的简单
public class Main {
public static void main(String[] args) {
System.out.println(Integer.toBinaryString(2019));
}
}
1200000的所有约数,一道填空题 没什么好说的,暴力破解就完事了
public class Main {
public static void main(String[] args) {
int count=0;
int n=1200000;
for (int i = 1; i <= 1200000; i++) {
if((n/i)*i==n){
count++;
}
}
System.out.println(count);
}
}
2019节点无向图最少边
无向图是什么我不清楚,所以直接蒙了个2018,貌似还蒙对了 。
1到2019内含9的数量 继续暴力破解
public class Main {
public static void main(String[] args) {
int count=0;
for (int i = 1; i <= 2019; i++) {
if (check(i)) {
count++;
}
}
System.out.println(count);
}
public static boolean check(int n) {
while (n != 0) {
if (n % 10 == 9) {
return true;
}
n/=10;
}
return false;
}
}
字符串中元辅音字母的数量 继续暴力破破破破
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
int count1=0,count2=0;
for (int i = 0; i < s.length(); i++) {
if (check(s.charAt(i))) {
count1++;
} else {
count2++;
}
}
System.out.println(count1);
System.out.println(count2);
}
public static boolean check(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
return true;
}
return false;
}
}
有n个数,求其中任意两个数组成m的倍数的倍数对有多少个 暴力破解
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int count=0;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] num = new int[n];
for (int i = 0; i < n; i++) {
num[i] = sc.nextInt();
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if ((num[i] + num[j]) % m == 0) {
count++;
}
}
}
System.out.println(count);
}
}
这是我自己的方法,也看了我们学校王跃坤大佬的代码,感觉同样是暴力破解,他的代码要比我写的更有美感
找出1到n内各个位上没有重复数字的个数 暴力破。。。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int count=0;
for (int i = 1; i <= n; i++) {
if(check(i)) count++;
}
System.out.println(count);
}
public static boolean check(int n) {
if(n<10) return true;
String s = n + "";
int[] t = new int[s.length()];
int index=0,count=1;
while (n != 0) {
t[index++]=n%10;
n/=10;
}
for (int i = 1; i < t.length; i++) {
if(t[i]==t[0]) count++;
}
return count != t.length;
}
}
走梅花桩,这道题写的挺懵的,先不写
两辆车运花,求两辆车最小重量差 还是暴力求解。。 这道题不确定对不对,但自己试了几个例子,都是正确的
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[][] t = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
t[i][j] = sc.nextInt();
}
}
int jj=m-1;
int min=Integer.MAX_VALUE;
while (jj != 0) {
int previous=0,after=0;
for (int i = m - 1; i >= jj; i--) {
for (int j = 0; j < n; j++) {
after += t[j][i];
}
}
for (int i = 0; i < jj; i++) {
for (int j = 0; j < n; j++) {
previous += t[j][i];
}
}
int x= Math.abs(after-previous);
if(x<min) min=x;
jj--;
}
System.out.println(min);
}
}
没看懂题。。。
总的还说,还是挺满意的,明年三月份还有蓝桥杯,这个才是真正的竞赛,这几个月一定要锻炼自己的算法能力,学习好数据结构,争取拿到一个好的名次