阿里笔试3 .25

阿里笔试3.25号题目,没参加这一场,试着写了下,测试了一个用例,通过了,不知道能不能AC
import java.util.Scanner;
public class Main3 {
    public static void main(String [] args){
        Scanner reader = new Scanner(System.in);
        int n = reader.nextInt();
        reader.nextLine();
        int [][] array = new int[3][n];
        for(int i = 0; i < 3;i++){
            for(int j = 0; j < n;j++){
                array[i][j] = reader.nextInt();
            }
            reader.nextLine();
        }
        int[][] dp = new int[n][3];
        for(int i = 0; i < n;i++){
            for(int j = 0; j < 3;j++){
                dp[i][j] = Integer.MAX_VALUE;
            }
        }
        dp[0][0] = 0;
        dp[0][1] = 0;
        dp[0][2] = 0;
        for(int i = 1;i < n;i++){
            for(int j = 0; j < 3;j++){  //  第i列的
                for(int k = 0;k < 3;k++){  // 第i - 1列的
                    int temp = dp[i - 1][k] + Math.abs(array[j][i] - array[k][i- 1]);
                    if(temp < dp[i][j]){
                        dp[i][j] = temp;
                    }
                }
            }
        }
        System.out.println(Math.min(dp[n - 1][0],Math.min(dp[n - 1][1],dp[n - 1][2])));
    }
}
测试用例
5
5 9 5 4 4
4 7 4 10 3
2 10 9 2 3
输出:5
第二题,没参加这期笔试,不知道能不能AC,测试用例过了
import java.util.Scanner;
public class Main4 {
    public static  void main(String [] args){
        //  读取数据
        Scanner reader = new Scanner(System.in);
        int m = reader.nextInt(); //  m行n列
        int n = reader.nextInt();
        int q = reader.nextInt();
        reader.nextLine();
        int [][] array = new int[m][n];
        for(int i = 0; i < m;i++){
            for(int j = 0; j < n; j++){
                array[i][j] = reader.nextInt();
            }
            reader.nextLine();
        }

        int[][] que = new int [q][2];
        for(int i = 0; i < q;i++){
            que[i][0] = reader.nextInt();
            que[i][1] = reader.nextInt();
            reader.nextLine();
        }

        //  开始填充
        boolean flag = true;
        while(flag){
            flag = false;
            //  遍历行进行填充
            for(int i = 0; i < m;i++){
                int left = -1;
                int right = -1;
                boolean temp_flag = false;
                for(int j = 0; j < n;j++){
                    if(array[i][j] != 0){
                        if(left == -1)left = j;
                        else if(right == -1){
                            right = j;
                            temp_flag = true;
                            break;
                        }
                    }
                }
                if(temp_flag){
                    int d = (array[i][right] - array[i][left])/(right - left);
                    for(int k = 0; k < m;k++){
                        if(array[i][k] == 0){
                            array[i][k] = array[i][right] - d * (right - k);
                            flag = true;
                        }
                    }
                }
            }
            //  遍历列进行填充
            for(int i = 0; i < n;i++){
                int up = -1;
                int down = -1;
                boolean temp_flag = false;
                for(int j = 0; j < m;j++){
                    if(array[j][i] != 0){
                        if(up == -1)up = j;
                        else if(down == -1){
                            down = j;
                            temp_flag = true;
                            break;
                        }
                    }
                }
                if(temp_flag){
                    int d = (array[down][i] - array[up][i])/(down - up);
                    for(int k = 0; k < m;k++){
                        if(array[k][i] == 0){
                            array[k][i] = array[down][i] - d * (down - k);
                            flag = true;
                        }
                    }
                }
            }
        }
        for(int i = 0; i < q;i++){
            if(array[que[i][0] - 1][que[i][1] - 1] != 0){
                System.out.println(array[que[i][0] - 1][que[i][1] - 1]);
            }
            else{
                System.out.println("Unknown");
            }
        }
    }
}



#阿里笔试##阿里巴巴##笔试题目#
全部评论
分享下我的题解:https://www.nowcoder.com/discuss/392312?toCommentId=5677651
点赞 回复 分享
发布于 2020-03-31 19:01

相关推荐

03-06 12:44
已编辑
门头沟学院 Java
是个千人厂,没听过名字。1.&nbsp;做一个自我介绍。2.&nbsp;你这个项目和技术栈从哪里学的?有报辅导班嘛[答&nbsp;都是是自己网上学的,学校教的东西没用]3.&nbsp;我看了你放在github上的项目,前端也是你写的嘛[答&nbsp;AI写的,90%精力用于后端开发,前端单纯用于作为后端逻辑的可视化技术验证(骗你的其实后端也是AI写的)]4.&nbsp;好,你觉得这些技术栈研究得最深刻的是哪个[答&nbsp;八股压根没背到后面,昨晚背了MySQL就说MySQL]5.&nbsp;那讲一下MySQL的索引[答&nbsp;从B+树选型一路吟唱到联合索引,索引失效]6.&nbsp;联合索引ABC问题,AB走索引嘛,BC走索引嘛?BAC走索引嘛?A&nbsp;or&nbsp;B&nbsp;走索引嘛[走,不走,走,不走。面试官点头说可以]7.&nbsp;讲一下项目里Redission分布式锁实现8.&nbsp;Watchdog机制具体是怎么工作9.&nbsp;消息队列有考虑过Kafka嘛,怎么选型的10.&nbsp;你这个项目消息队列可能出现什么问题,怎么解决这个问题?[瞎扯没用的,被面试官引导答了视频处理可能产生消息堆积问题,然后开始吟唱]11.&nbsp;文件分片自己写的还是用的什么框架?上传进度的Redis数据结构?上传的视频有多大?小分片大小?12.&nbsp;项目里Redis会话记忆是啥意思?[面试官说不行,没人把这个全放Redis里[生气R]]13.&nbsp;那这和直接查数据库有什么区别[扯了Token成本和解决幻觉问题之类的,给面试官听笑了,我最后也没绷住]14.&nbsp;你平时是怎么使用AI&nbsp;coding的15.&nbsp;算法,给了我一个leedcode链接,一看做过了。然后换了一道三数之和,也做过了。然后面试官说算了,让我讲讲思路吧反问:1.有什么需要提高的地方2.介绍一下部门业务有哪些这个面试官真的感官非常非常好,问问题还疯狂引导,感觉不会也会了。找实习&nbsp;&nbsp;牛客AI配图神器#
查看15道真题和解析
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务