腾讯java工程师笔试题,腾讯开发岗笔试题解Java

第一题:就是一个找规律

public class Q1 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

long n = sc.nextInt();

long m = sc.nextInt();

long count = m * m;

long sum = n / (2 * m) * count;

System.out.println(sum);

}

}

第二题:dp

public class Q2 {

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]);

}

}

第三题:贪心,排序求和

public class Q3 {

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];

// sort

Comparator 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);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值