滴滴秋招笔试题(2016-09-18)

我是刺客 我是刺客     2022-08-05     258

关键词:

 

1.地下迷宫

这道题是网上找到别人的答案,拿过来学习学习,望勿怪。

 

技术分享

 

技术分享

 

技术分享

import java.io.BufferedInputStream;
import java.util.Scanner;

public class 地下迷宫 {
    public static int[][] dir = { { 1, 0, 0 }, { 0, 1, 1 }, { -1, 0, 3 }, { 0, -1, 1 } };
    public static int n = 0;
    public static int m = 0;
    public static int p = 0;
    public static int[][] min = new int[2][300];
    public static int[][] curr = new int[2][300];
    public static int mintime = Integer.MAX_VALUE;
    public static int currtime = 0;
    public static int steps = 0;
    public static int beststeps = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        n = scanner.nextInt();
        m = scanner.nextInt();
        p = scanner.nextInt();
        int[][] maze = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                maze[i][j] = scanner.nextInt();
            }
        }
        scanner.close();
        maze[0][0] = 0;
        go(0, 0, maze);
        if (mintime == Integer.MAX_VALUE)
            System.out.println("Can not escape!");
        else {
            System.out.print("[" + min[0][0] + "," + min[1][0] + "]");
            for (int i = 1; i < beststeps; i++) {
                System.out.print(",[" + min[0][i] + "," + min[1][i] + "]");
            }
            System.out.print(",[" + 0 + "," + (m - 1) + "]");
        }
    }

    public static void go(int a, int b, int[][] maze) {
        if (a == 0 && b == m - 1) {
            if (p >= currtime) {
                if (currtime < mintime) {
                    mintime = currtime;
                    min = curr.clone();
                    beststeps = steps;
                }
            }
        }
        for (int i = 0; i < 4; i++) {
            if (cango(a, b, dir[i][0], dir[i][1], maze)) {
                steps++;
                curr[0][steps] = a + dir[i][0];
                curr[1][steps] = b + dir[i][1];
                currtime += dir[i][2];
                maze[a + dir[i][0]][b + dir[i][1]] = 0;
                go(a + dir[i][0], b + dir[i][1], maze);
                maze[a + dir[i][0]][b + dir[i][1]] = 1;
                currtime -= dir[i][2];
                steps--;
            }
        }
    }

    public static boolean cango(int i, int j, int a, int b, int[][] maze) {
        if (i + a >= 0 && i + a < n && j + b >= 0 && j + b < m && maze[i + a][j + b] == 1 && p >= currtime)
            return true;
        return false;
    }
}

 

 

2.末尾0的个数

输入一个正整数n,求n!末尾有多少个0;比如n=10;10!=3628800;所以答案为2;1<=n<=1000.

解析:我在做的时候没有注意到随着n的增大,阶数是特别大的,基本数据类型装不下,所有需要边做阶乘,边去计算末尾0的个数,然后把这个阶乘除以10.使其变小,以便能够存储下。

public class 末尾0的个数 {

    public static void main(String[] args) {
        int n = 100;
        int c = getCount(n);
        System.out.println(c);
    }

    private static int getCount(int n) {
        int sum = 1;
        int c = 0;
        for (int i = 1; i <= n; i++) {
            sum *= i;
            if (sum % 10 == 0) {
                c++;
                sum = sum / 10;
            }
        }
        return c;
    }

}

 

网易2017秋招笔试题3:最长公共子括号序列长度

【问题来源】网传的2017网易秋招笔试题【问题描述】 【算法思路】 下面的解题思路摘自 http://www.cnblogs.com/Atanisi/p/7500186.html刚看到题我就想到暴力解,深搜出所有合法的括号序列,再依次比较公共子序列的长度,返... 查看详情

tx2017秋招笔试题之素数对

问题描述:给定一个正整数,编写程序计算有多少对质数的和等于输入的这个正整数,并输出结果。输入值小于1000。如,输入为10,程序应该输出结果为2。(共有两对质数的和为10,分别为(5,5),(3,7))输入描述:输入包括一个整数n,(3... 查看详情

美团2017秋招笔试题拼凑钱币

给你六种面额1、5、10、20、50、100元的纸币,假设每种币值的数量都足够多,编写程序求组成N元(N为0~10000的非负整数)的不同组合的个数。 输入描述:输入包括一个整数n(1≤n≤10000)输出描述:输出一个整数,表示不同的组合方... 查看详情

2017腾讯秋招笔试题之编码

Description:  假定一种编码的编码范围是a~y的25个字母,从1位到4位的编码,如果我们把该编码按字典序排序,形成一个数组如下:a,aa,aaa,aaaa,aaab,aaac,……,b,ba,baa,baaa,baab,baac……,yyyw,yyyx,yyyy其中a的Index为0,aa的Index为1,aaa的... 查看详情

2017腾讯秋招笔试题之编码

Description:  假定一种编码的编码范围是a~y的25个字母,从1位到4位的编码,如果我们把该编码按字典序排序,形成一个数组如下:a,aa,aaa,aaaa,aaab,aaac,……,b,ba,baa,baaa,baab,baac……,yyyw,yyyx,yyyy其中a的Index为0,aa的Index为1,aaa的... 查看详情

tx2017秋招笔试题之编码

问题描述:假定一种编码的编码范围是a~y的25个字母,从1位到4位的编码,如果我们把该编码按字典序排序,形成一个数组如下:a,aa,aaa,aaaa,aaab,aaac,……,b,ba,baa,baaa,baab,baac……,yyyw,yyyx,yyyy其中a的Index为0,aa的Index为1,aaa的Index为2... 查看详情

阿里巴巴2021秋招笔试题20210806(代码片段)

源代码:https://gitee.com/shentuzhigang/mini-project/tree/master/exam-alibaba/exam-alibaba-20210806第一题题目描述大概定义了一年mmm个月,一个月ddd天,一周www天已知mmm,ddd,www求第kkk年,第jjj月 查看详情

tx2017秋招笔试题之geohash编码

问题描述:geohash编码:geohash常用于将二维的经纬度转换为字符串,分为两步:第一步是经纬度的二进制编码,第二步是base32转码。此题考察纬度的二进制编码:算法对纬度[-90,90]通过二分法进行无限逼近(取决于所需精度,本... 查看详情

序列和-------一道大厂秋招笔试题(代码片段)

题目:给出一个正整数N和长度L,找出一段长度大于等于L的连续非负整数,他们的和恰好为N。答案可能有多个,我我们需要找出长度最小的那个。例如N=18L=2:5+6+7=183+4+5+6=18都是满足要求的,但是我们输出更短的567综合网上给出... 查看详情

阿里巴巴2021秋招笔试题20211119(代码片段)

源代码:https://gitee.com/shentuzhigang/algorithm/tree/master/exam-alibaba/exam-alibaba-20211119第一题题目大意:有长度为n的数组a有k次机会在连续长度不超过m的区间每个元素+1使得数组全部元素变成偶数importjava.util.LinkedList;importjava.util... 查看详情

微软2017校招笔试题2composition

题目AlicewritesanEnglishcompositionwithalengthofNcharacters.However,herteacherrequiresthatMillegalpairsofcharacterscannotbeadjacent,andif‘ab‘cannotbeadjacent,‘ba‘cannotbeadjacenteither.Inordertomeetther 查看详情

微软2017校招笔试题3registrationday

题目It‘sHUniversity‘sRegistrationDayfornewstudents.ThereareMofficesinHUniversity,numberedfrom1toM.Studentsneedtovisitsomeoftheminacertainordertofinishtheirregistrationprocedures.Theofficesareindifferent 查看详情

互联网校招笔试题分享

Java一些知识点Object有哪些方法public 方法:getClass、equals(和==之间的区别)、hashCode、toString、wait、notifyprotected 方法:clone、finalizeprivate 方法:registerNatives,该方法作用是将不同平台C/C++实现的方法映射到Java中的native... 查看详情

华为补招笔试题20171130

注:实现时无需考虑不合法的情况。解答过程:感觉没有问题,可后来通过率才37.5%,puzzle。#include<iostream>usingnamespacestd;#include<string>#include<vector>#include<algorithm>//转化为大写stringstrToUpper(string&str){f 查看详情

小米2017校招笔试题

只过了20%...我日树的高度 时间限制:C/C++语言1000MS;其他语言3000MS 内存限制:C/C++语言65536KB;其他语言589824KB 题目描述: 现在有一棵合法的二叉树,树的节点都是用数字表示, 现在给定这棵树上所有的父子关系,求这棵树的高... 查看详情

奇虎3602017校招笔试题

最强大脑时间限制:C/C++语言1000MS;其他语言3000MS内存限制:C/C++语言65536KB;其他语言589824KB题目描述:小B乘火车和朋友们一起在N市到M市之间旅行。她在路途中时睡时醒。当她醒来观看窗外的风景时,注意到每个火车站都有一... 查看详情

2017华为优招笔试题

 哎,没有接到笔试通知,不知道为啥就错过了。之后见到题目,前两道编程题。其实都见过类似的题目,有点思路,但是直接快速完整实现出来,水平还是达不到。这样的题目,也不算难,三道编程题至少AC两道才算可以。... 查看详情

lgyx2017校招笔试题

前言今天通知过了笔试,但总感觉有些笔试没来得及做的题不解决不舒服斯基。题目 大意就是,给你个形如a,b,c,ab,bb,cb,ac,bc,cc,aab,bab,cab,abb,bbb,cbb,acb,bcb,ccb......按某种规律排列的无限长的字符串数组,要求:1)给定一个位置,... 查看详情