科大讯飞0723笔试
25单选题+3编程题
单选对于我来说还是好难啊😥😥
1、求个汉宁窗映射的值,具体题目记不清了,大概就直接按照题目给的公式计算就行了。
这个题目有个坑,给的Pi=3.1516927不能直接用数字,我直接用数字计算就只有70%,因为默认是double类型的,要用个变量Pi存成float类型计算。
2、求给定点中能组成直角三角形的个数。数据量不是很大,而且提示也说可以用勾股定理,所以直接暴力计算就行。感觉用向量点积应该计算更少点。
3、5个球队一个小组,踢10场比赛。赢比赛得3分,输比赛得0分,平局双方各得1分。求最终5支球队得分情况的总数(得分排列需要按照降序去重),以及输入一个序列判断是不是可能的最终得分情况。
笔试的时候没写出来,只想到要用回溯,笔试完了才把细节和去重部分补全了。贴一下:
public class Main{
static int[][] games = {{0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}};
static Set<Scores> set = new HashSet<>();
static int[][] score = {{3, 0}, {1, 1}, {0, 3}}; // main里用dfs(0, new int[5])调用
private void dfs(int idx, int[] cur) {
if (idx == 10) {
int[] copy = Arrays.copyOfRange(cur, 0, 5);
Arrays.sort(copy);
swap(copy, 0, 4);
swap(copy, 1, 3);
set.add(new Scores(copy[0], copy[1], copy[2], copy[3], copy[4]));
return;
}
for (int j = 0; j < 3; j++) {
cur[games[idx][0]] += score[j][0];
cur[games[idx][1]] += score[j][1];
dfs(idx + 1, cur);
cur[games[idx][0]] -= score[j][0];
cur[games[idx][1]] -= score[j][1];
}
}
private void swap(int[] cur, int i, int j) {
int temp = cur[j];
cur[j] = cur[i];
cur[i] = temp;
}
}
class Scores {
int a, b, c, d, e;
public Scores(int a, int b, int c, int d, int e) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Scores scores = (Scores) o;
return a == scores.a && b == scores.b && c == scores.c && d == scores.d && e == scores.e;
}
@Override
public int hashCode() {
return Objects.hash(a, b, c, d, e);
}
}