滴滴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 广东

相关推荐

03-29 12:10
门头沟学院 C++
挣K存W养DOG:散漫消极者淘汰,一眼坑爹。实习几个月转正的时候说你加班太少,能力还行态度不够积极裁了,马上老实。
点赞 评论 收藏
分享
03-19 10:07
已编辑
广东药科大学 golang
Yki_:你倒是进一个面啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务