Pony.ai 笔试

第一题 暴力AC

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int[] check(int[] a) {
        int n = a.length;
        int[] c = new int[n];
        c[0] = a[0];
        int d = a[1] - a[0];
        for (int i = 1; i < n; i++) {
            c[i] = c[i - 1] + d;
            if (c[i] < 0) {
                return null;
            }
            if (c[i] % a[i] > 0) {
                return null;
            }
            int t = c[i] / a[i];
            if ((t & (t - 1)) != 0) {
                return null;
            }
        }
        return c;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int x = a[0];
        int y = a[1];
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                a[0] <<= i;
                a[1] <<= j;
                int[] c = check(a);
                if (c != null) {
                    Arrays.stream(c).forEach(System.out::println);
                    return;
                }
                a[0] = x;
                a[1] = y;
            }
        }
    }
}

第二题. 76%
最后2分钟想到坑点了

BBBBBW
WWWW..
BBBBBW
WWWW..

这种情况是不合法的
但是

BBBBB
....B
....B
....B
....B

是合法的。
可惜已经没空写了。
第三题。物理渣。理化生就物理最差。混了个64%。刚刚看有个大佬AC了,也发帖了,可以参考他的。

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        while (n-- > 0) {
            /*
            x = rcosθ+x0-r
            y = rsinθ+y0
             */
            double l0, v0, l1, v1, x0, y0, r, x1, y1;
            l0 = in.nextInt();
            v0 = in.nextInt();
            l1 = in.nextInt();
            v1 = in.nextInt();
            x0 = in.nextInt();
            y0 = in.nextInt();
            r = in.nextInt();
            x1 = in.nextInt();
            y1 = in.nextInt();
            double θ = Math.acos((x1 + r - x0) / r);
            double inR = θ * r;
            double outR = inR + l0;
            double tAin = inR / v0;
            double tAout = outR / v0; // tAin .. tAout
            double y2 = r*Math.sin(θ)+y0;
            double y3 = y2-l1;
            double tBin = (y1 - y2) / v1;
            double tBout = (y1 - y3) / v1;
            if (tAout <= tBin  || tBout <= tAin) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        }
    }
}
#笔试题目##题解##小马智行#
全部评论
第二题直接搜索79% import sys def dfs(board, x, y, last_dir, count, cls):     if count == 5:         return True     if not last_dir:         for each_dir in DIR:             temp_x = x + each_dir[0]             temp_y = y + each_dir[1]             if 0 <= temp_x < N and 0 <= temp_y < N and board[temp_x][temp_y] == cls:                 rvt = dfs(board, temp_x, temp_y, each_dir, count + 1, cls)                 if rvt:                     return True     else:         temp_x = x + last_dir[0]         temp_y = y + last_dir[1]         if 0 <= temp_x < N and 0 <= temp_y < N and board[temp_x][temp_y] == cls:             rvt = dfs(board, temp_x, temp_y, last_dir, count + 1, cls)             if rvt:                 return True     return False if __name__ == '__main__':     N = 15     DIR = [[1, 0], [0, 1], [-1, 1], [1, 1]]     chess_board = []     for i in range(N):         temp = sys.stdin.readline().strip()         chess_board.append(temp)     count_white, count_black = 0, 0     for i in range(N):         count_white += chess_board[i].count('W')         count_black += chess_board[i].count('B')     if count_white > count_black or count_black > count_white + 1:         print("invalid board")     else:         rvt_w, rvt_b = False, False         for i in range(N):             if rvt_w:                 break             for j in range(N):                 if chess_board[i][j] == 'W':                     rvt_w = dfs(chess_board, i, j, None, 1, 'W')                     if rvt_w:                         break         for i in range(N):             if rvt_b:                 break             for j in range(N):                 if chess_board[i][j] == 'B':                     rvt_b = dfs(chess_board, i, j, None, 1, 'B')                     if rvt_b:                         break         if not rvt_w and not rvt_b:             if count_white + count_black == N * N:                 print("draw")             else:                 print("not finished")         elif rvt_w:             if count_white == count_white:                 print("white win")             else:                 print("invalid board")         elif rvt_b:             if count_black > count_white:                 print("black win")             else:                 print("invalid board")
2 回复
分享
发布于 2018-09-19 22:51
第二题我估计要很久,找了个48%就跳过去了,做完第三题剩几分钟,就没做第二题,求分享第二题思路
点赞 回复
分享
发布于 2018-09-19 22:42
联想
校招火热招聘中
官网直投
去面过了,前面主要就是写题,后面换人瞎聊
点赞 回复
分享
发布于 2018-09-20 01:36

相关推荐

点赞 9 评论
分享
牛客网
牛客企业服务