滴滴0928笔试,第一题只过了55%


import java.util.*;
public class Main {
    static int n;
    static HashSet<String> hashSet = new HashSet<>();
    static HashSet<String> ans = new HashSet<>();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        cut(a, b, c, 1);
        System.out.println(ans.size());
    }

    public static void cut(int a, int b, int c, int now) {//剩余now次
        if ( a <= 0 || b <= 0 || c <= 0 || now >n || hashSet.contains(a+","+b+","+c)) {
            return;
        }
        hashSet.add(a+","+b+","+c);
        if (a + b > c && a + c > b && b + c > a) {
            ans.add(a+","+b+","+c+","+now);
        }
        cut(a - now, b, c, now + 1);
        cut(a, b - now, c, now + 1);
        cut(a, b, c - now, now + 1);
    }

}

一份只过了55%的代码,有大佬帮忙分享一下解题思路吗

全部评论
首先可能有cut 0次的情况 其次当abc已经在set中就应该不再搜索
点赞 回复 分享
发布于 2023-09-28 21:39 江苏
过73% 完全不明白惹
点赞 回复 分享
发布于 2023-09-28 20:48 上海
我过了82...
点赞 回复 分享
发布于 2023-09-28 20:47 广东

相关推荐

点赞 评论 收藏
分享
一表renzha:你点进去没打招呼他也会有提示的,之前我点进美的,还没打招呼,他马上给我发了不太合适哦
点赞 评论 收藏
分享
05-09 12:23
已编辑
华南理工大学 Java
野猪不是猪🐗:给他装的,双九+有实习的能看的上这种厂我直接吃⑨✌们拿它练练面试愣是给他整出幻觉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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