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

相关推荐

点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
05-22 17:07
已编辑
门头沟学院 Java
程序员牛肉:都啥时候了还jb打蓝桥杯呢,有限找实习。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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