赞
踩
B卷:
一、爱玩游戏的小J
大概意思:每一个游戏都有一个成就值和时间消耗,问在给定的时间内,小J最多能收获多少成就值
典型的01背包问题:
- import java.util.Scanner;
-
- public class xx {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
-
- int t = sc.nextInt();
- while(t>0) {
- int n = sc.nextInt();
- int m = sc.nextInt();
-
- int v[] = new int[n+1];
- int w[] = new int[n+1];
-
- for (int i = 1; i < n+1; i++) {
- v[i] = sc.nextInt();
- w[i] = sc.nextInt();
- }
-
- int dp[][] = new int[n+1][m+1];
-
- for (int i = 1; i < n+1; i++) {
- for (int j = 1; j < m+1; j++) {
- if(w[i]>j) {
- dp[i][j] = dp[i-1][j];
- }else {
- dp[i][j] = Math.max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
- }
- }
- }
-
- System.out.println(dp[n][m]);
- t = t-1;
- }
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
二、不听话的机器人
根据给出的字符串指令,替换语句中的字符串
字符串替换,最简单一个:
- import java.util.Scanner;
-
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- while (sc.hasNext()){
- int mapItem = sc.nextInt();
- int debugItem = sc.nextInt();
- String mapArray[][] = new String[mapItem][2];
- for (int i = 0; i < mapArray.length; i++) {
- for (int j = 0; j < mapArray[0].length; j++) {
- mapArray[i][j] = sc.next();
- }
- }
- String inputArray[] = new String[debugItem];
- for (int i = 0; i < inputArray.length; i++) {
- inputArray[i]= sc.next();
- }
- for (int i = 0; i < inputArray.length; i++) {
- for (int j = 0; j < mapArray.length; j++) {
- if (inputArray[i].equals(mapArray[j][0])){
- System.out.println(mapArray[j][1]);
- }
- }
- }
- }
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
三、应该怎么吃
大概意思:有很多零食,问正好花掉X元的情况下,有多少种吃法,其中这个人对每个零食的喜爱程度不一样,喜爱程度高的零食必须多余比它喜爱程度低的零食个数要多,问有多少种情况,最终结果可能很大,要求结果%10000007
没时间写了,时间要求三秒,感觉可以暴力试一下~
听说A卷是一道基础编程,一道动态规划,一道最短路径,感觉A卷难度适中,B卷最后一题思路不清,前两个简单。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。