概述
第一题:
public class Main {
public static void main(String[] args) {Scanner sc = new Scanner(System.in);
long n = sc.nextInt();
long m = sc.nextInt();
long sum = n/2 * m;
System.out.println(sum);
}
}
第二题:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int a = sc.nextInt();
int x = sc.nextInt();
int b = sc.nextInt();
int y = sc.nextInt();
int[][] dp = new int[x+y+1][k+1];
for (int i = 0; i < x+y+1; i++)
dp[i][0] = 1;
for (int i = 1; i < x+y+1; i++) {
for (int j = 1; j <= k; j++) {
if (i <= x) {
if (j >= a)
dp[i][j] = (dp[i-1][j] + dp[i-1][j-a]) % 1000000007;
else dp[i][j] = dp[i-1][j] % 1000000007;
}
else if (i <= x+y) {
if (j >= b)
dp[i][j] = (dp[i-1][j] + dp[i-1][j-b]) % 1000000007;
else
dp[i][j] = dp[i-1][j] % 1000000007;
}
}
}
System.out.println(dp[x+y][k]);
}
}
第三题:(我没时间了,所以没写出来,这个是从大神那Copy过来的)
import java.util.*;
public class Main {
static class Pair {
int time;
int level;
public Pair(int time, int level) {
this.time = time;
this.level = level;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
Pair[] machine = new Pair[n];
Pair[] task = new Pair[m];
// input
for (int i = 0; i < n; i++)
machine[i] = new Pair(sc.nextInt(), sc.nextInt());
for (int i = 0; i < m; i++)
task[i] = new Pair(sc.nextInt(), sc.nextInt());
int[] cnt = new int[105];
Comparator<Pair> comparator = (a, b) -> {
if (a.time == b.time) return b.level - a.level;
else return b.time - a.time;
};
Arrays.sort(machine, comparator);
Arrays.sort(task, comparator);
long sum = 0;
int j = 0, cnt1 = 0;
for(int i = 0;i < m;i++) {
while(j < n && machine[j].time >= task[i].time) {
cnt[machine[j].level]++;
j++;
}
for(int k = task[i].level; k < 101; k++) {
if(cnt[k] != 0) {
cnt[k]--;
sum += 200*task[i].time + 3*task[i].level;
cnt1++;
break;
}
}
}
System.out.println(cnt1 + " " + sum);
}
}
最后
以上就是大气鞋垫为你收集整理的腾讯开发岗笔试题Java的全部内容,希望文章能够帮你解决腾讯开发岗笔试题Java所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复