10.25美团笔试 求问第3题

我的代码一直输出错误,样例都过不了,是我的思路出问题了吗,求各位大佬解答 顺便求345AC代码 第4题骗分骗了0.27 完全没有思路
import java.util.Scanner;

public class Main 
{
    public static void main(String[] args)
    {
    	Scanner s = new Scanner(System.in);
		int n = s.nextInt();
        int [] a = new int [n];
        int [] b = new int [n];
        for(int i = 0;i < n;i++)
        {
            a[i] = s.nextInt();
        }
        check(a,b);
    }
    
    public static void check(int [] a,int [] b)
    {
        for(int i = 0;i < b.length;i++)//计算bi的值
        {
            int temp1 = a[i];
            for(int j = 0;j < a.length;j++)
            {
                int temp2 = (i + 1) % (j + 1);//mod
                temp1 = func(temp1,temp2);
            }
            b[i] = temp1;
        }
        int res = b[0];
        for(int i = 1;i < b.length;i++)
        {
            res = func(res,b[i]);
        }
        System.out.println(res);
    }
    
    public static int func(int a,int b)//异或运算
    {
        if(a == b) return 0;
        return a;
    }
}


#笔试题目##美团#
全部评论
这题是数学问题,一个异或本身等于0,所以可以排除掉重复的子项,1到n的取余矩阵中最终剩下不到n个子项,这时候再来跟输入进行异或就不超时了
2 回复 分享
发布于 2020-10-25 12:38
有收到面试吗
点赞 回复 分享
发布于 2020-10-29 09:35
大佬们帮我看看为啥第一题超时了,顺便求第四题思路 n, p, q = map(int, input().split()) listp = list(map(int, input().split())) listq = list(map(int, input().split())) both = [] for i in range(p):     if listp[i] in listq:         both.append(listp[i])         listq.remove(listp[i])          print(p - len(both),end = ' &(5528)#39;) print(len(listq),end = ' &(5528)#39;) print(len(both))
点赞 回复 分享
发布于 2020-10-26 22:03
    base = 2     count = 0     while base < max(x, y):         base *= 2         count += 1     result = 0     while base >= 2:         if x <= base / 2 and y <= base / 2:                        result += 0             x = x             y = y                    if x <= base / 2 and y > base / 2:                         result += a             x = x             y = y - 2 ** count                    if x > base / 2 and y <= base / 2:                          result += b             x = x - 2 ** count             y = y                    if x > base / 2 and y > base / 2:                          result += c             x = x - 2 ** count             y = y - 2 ** count         base /= 2         count -= 1     print(result)
点赞 回复 分享
发布于 2020-10-26 01:33
有木有题目呀
点赞 回复 分享
发布于 2020-10-25 13:24
请问大家第二题不就是计算Math.abs(len/2-小写字母的个数)吗,一直是45%,是我想法错了嘛救救孩子
点赞 回复 分享
发布于 2020-10-25 12:40
思路没问题,两个数的取值都是0-10w,0.27剩下的都是超时。
点赞 回复 分享
发布于 2020-10-25 12:29
5题目,一共a多少?
点赞 回复 分享
发布于 2020-10-25 12:28
同求3,4AC参考
点赞 回复 分享
发布于 2020-10-25 12:27
第四题时间不够没想出来,不过我骗分骗的比你多一点😂判断三个条件:没有偶数,有一个等于n,还有排序之后最中间的那个数是1,骗到了45%的分🤣
点赞 回复 分享
发布于 2020-10-25 12:24
你的func函数有问题,异或不是这么算的,java里有异或符号^你可以直接用的。另外你这个方法就算改对也只能过55%,我的就是,我也没找到更快的方法。
点赞 回复 分享
发布于 2020-10-25 12:21

相关推荐

评论
1
3
分享

创作者周榜

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