您当前的位置: 首页 > 

TechGuide

暂无认证

  • 4浏览

    0关注

    176博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

搜狗三道编程题整理(2020/09/05)

TechGuide 发布时间:2020-09-05 20:48:45 ,浏览量:4

备战秋招面试 微信搜索公众号【TechGuide】关注更多新鲜好文和互联网大厂的笔经面经。 作者@TechGuide 点赞再看,养成习惯,您动动手指对原创作者意义非凡🤝

第一题,汪仔换道具,主要思路就是先减去直接换的,然后排序,此时a=0,分为两种情况,b,c给a,以及c给b和a。设x解方程就可以求出表达式

方法一:

作者:千草幽幽
链接:https://www.nowcoder.com/discuss/500293?type=0&order=0&pos=7&page=1&channel=666&source_id=discuss_center_0
来源:牛客网

class Solution:
    def numberofprize(self , a , b , c ):
        # write code here
        res = 0
        res+= min(a,b,c)
        a -= res
        b -= res
        c -= res
        a,b,c = sorted([a,b,c])
         
        return min(res + (2*b+c)//5,res + (b+c)//4)

方法二:

作者:neebie
链接:https://www.nowcoder.com/discuss/500271?type=all&order=time&pos=&page=1&channel=666&source_id=search_all
来源:牛客网
public int numberofprize (int a, int b, int c) {
        // write code here
        int left=min(a,b,c);
        int right=max(a,b,c);
        while (left=mid){
            left+=(a-mid);
        }else {
            left-=(2*(mid-a));
        }
        if (b>=mid){
            left+=(b-mid);
        }else {
            left-=(2*(mid-b));
        }
        if (c>mid){
            left+=(c-mid);
        }else {
            left-=(2*(mid-c));
        }
        return left>=0;
    }

    private int min(int a, int b, int c) {
        return Math.min(Math.min(a,b),c);
    }
    private int max(int a, int b, int c) {
        return Math.max(Math.max(a,b),c);
    }

第二题,建房子,思路是找房子间隔,大于t就+2,等于t就+1,最后考虑最左和最右,+2就可以了

class Solution:
    def getHouses(self , t , xa ):
        # write code here
        res = 0
        for i in range(0,len(xa),2):
            xa[i],xa[i+1] = xa[i]-xa[i+1]/2,xa[i]+xa[i+1]/2
        for i in range(len(xa)//2 -1):
            if xa[2*i+2] - xa[2*i+1] == t:
                res += 1
            elif xa[2*i+2] - xa[2*i+1] > t:
                res += 2
        return res+2

方法二:

public int getHouses (int t, int[] xa) {
        // write code here
        if (xa==null||xa.length==0)
            return 0;
        double[][] xAndA=new double[xa.length/2][2];
        int idx=0;
        for (int i = 0; i =j:return 0
            n = j-i+1
            Ex = (prex[j+1]-prex[i])/n
            Ex2 = (prex2[j+1]-prex2[i])/n
            return Ex2-Ex**2
        v = float('inf')
        res = 0
        for i in range(0,n):
            temp = abs(var(0,i-1) + var(i,n-1))
            if temp             
关注
打赏
1665329535
查看更多评论
0.0438s