12.7-12.13

算法解析:矩阵翻转、斐波那契数列、路径规划与找零问题
博客涵盖了多种算法问题的解决方案,包括翻转矩阵以获得最大得分,将字符串拆分为斐波那契数列,找出网格中的唯一路径,柠檬水找零的最优化策略,以及预测Dota2参议院的胜利方。这些内容涉及数据结构、递归、动态规划和博弈论等编程技巧。

12月7日

861.翻转矩阵后的得分

class Solution {
    public int matrixScore(int[][] A) {
        //1最多的时候数最大,先让最大位都为1
        int m = A.length, n = A[0].length;
        //最大位都为1的总和
        int ans = (1<<(n - 1)) * m;
        //遍历除第一列的所有列,让其每列的1最多
        for (int j = 1; j < n; j ++) {
            int num = 0;
            for (int i = 0; i < m; i ++) {
                //需判断它的最大位是否已经颠倒过
                num += A[i][0] == 1 ? A[i][j] : 1 - A[i][j];
            }
            ans += Math.max(num, m-num) * (1<<(n-j-1));
        }
        return ans;
    }
}

12月8日

842.将数组拆分为斐波那契数列

class Solution {
    public List<Integer> splitIntoFibonacci(String S) {
        List<Integer> ans = new ArrayList();
        backTrack(S.toCharArray(), ans, 0);
        return ans;
    }
    public boolean backTrack(char[] arr, List<Integer> ans, int index) {
        //递归结束条件
        if(index == arr.length && ans.size() >= 3) {
            return true;
        }
        for(int i = index; i < arr.length; i ++) {
            //如果是两位以上数且0开头,则退出
            if(arr[index] == '0' && i > index) {
                break;
            }
            //截取数
            long n = sToInt(arr, index, i+1);
            if(n > Integer.MAX_VALUE){
                break;
            }
            int size = ans.size();
            //如果截取的数大于ans里前两个数的和,退出
            if(size >= 2 && n > ans.get(size-2) + ans.get(size-1)) {
                break;
            }
            //如果ans中的数小于2个,直接添加截取的数,如果截取的数等于ans中前两个数的和,也添加入队
            if(size <= 1 || n == ans.get(size-2) + ans.get(size-1)) {
                ans.add((int)n);
                //递归判断剩下的数,如果出现不满足的,则出队
                if(backTrack(arr, ans, i + 1)) {
                    return true;
                } else {
                    ans.remove(ans.size() - 1);
                }
            }
        }
        return false;
    }
    //相当于截取字符串S中的子串然后转换为十进制数字
    private long sToInt(char[] arr, int start, int end) {
        long res = 0;
        for (int i = start; i < end; i++) {
            res = res * 10 + arr[i] - '0';
        }
        return res;
    }
}

12月9日

62.不同路径

class Solution {
    public int uniquePaths(int m, int n) {
        int[][] temp = new int[m][n];
        for(int i = 0; i < m; i ++) {
            for(int j = 0; j < n; j ++) {
                if(i == 0 || j == 0) {
                    temp[i][j] = 1;
                    continue;
                } else {
                    temp[i][j] = temp[i - 1][j] + temp[i][j - 1];
                }
            }
        }
        return temp[m-1][n-1];
    }
}

12月10日

/*
分别计算5、10的个数,因为20不用于找零,可以不统计数量
如果5和10少于0则返回false
*/
class Solution {
    public boolean lemonadeChange(int[] bills) {
        int five = 0, ten = 0;
        for(int i = 0; i < bills.length; i ++) {
            if(bills[i] == 5) {
                five ++;
            }else if(bills[i] == 10) {
                five --;
                ten ++;
            }else{
                if(ten > 0) {
                    ten --;
                    five --;
                } else {
                    five -=3;
                }
            }
            if(five < 0 || ten < 0) {
                return false;
            }
        }
        return true;
    }
}

12月11日

649.Dota2参议院

/*
先统计Radiant(天辉)和 Dire(夜魇)的下标
比较下标,下标小的可以参加第二轮投票,即重新入队
*/
class Solution {
    public String predictPartyVictory(String senate) {
        Queue<Integer> r = new LinkedList<>();
        Queue<Integer> d = new LinkedList<>();
        char[] s = senate.toCharArray();
        for(int i = 0; i < s.length; i ++) {
            if(s[i] == 'R') {
                r.offer(i);
            } else {
                d.offer(i);
            }
        }
        while(!r.isEmpty() && !d.isEmpty()) {
            int t1 = r.remove();
            int t2 = d.remove();
            if(t1 < t2) {
                r.offer(t1 + s.length);
            } else {
                d.offer(t2 + s.length);
            }
        }
        return d.isEmpty() ? "Radiant" : "Dire";
    }
}

12月13日

217.存在重复元素

class Solution {
    public boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int i : nums) {
            set.add(i);
        }
        return set.size() < nums.length;
    }
}
class Solution {
    public boolean containsDuplicate(int[] nums) {
        Arrays.sort(nums);
        for(int i = 0; i < nums.length - 1; i ++) {
            if(nums[i] == nums[i+1]) {
                return true;
            }
        }
        return false;
    }
}
【电动汽车充电站有序充电调度的分散式优化】基于蒙特卡诺和拉格朗日的电动汽车优化调度(分时电价调度)(Matlab代码实现)内容概要:本文介绍了基于蒙特卡洛和拉格朗日方法的电动汽车充电站有序充电调度优化方案,重点在于采用分散式优化策略应对分时电价机制下的充电需求管理。通过构建数学模型,结合不确定性因素如用户充电行为和电网负荷波动,利用蒙特卡洛模拟生成大量场景,并运用拉格朗日松弛法对复杂问题进行分解求解,从而实现全局最优或近似最优的充电调度计划。该方法有效降低了电网峰值负荷压力,提升了充电站运营效率与经济效益,同时兼顾用户充电便利性。 适合人群:具备一定电力系统、优化算法和Matlab编程基础的高校研究生、科研人员及从事智能电网、电动汽车相关领域的工程技术人员。 使用场景及目标:①应用于电动汽车充电站的日常运营管理,优化充电负荷分布;②服务于城市智能交通系统规划,提升电网与交通系统的协同水平;③作为学术研究案例,用于验证分散式优化算法在复杂能源系统中的有效性。 阅读建议:建议读者结合Matlab代码实现部分,深入理解蒙特卡洛模拟与拉格朗日松弛法的具体实施步骤,重点关注场景生成、约束处理与迭代收敛过程,以便在实际项目中灵活应用与改进。
0x000000000b01626c CitySample!FVulkanCommandBufferManager::PrepareForNewActiveCommandBuffer()() 0x000000000b0e8901 CitySample!FVulkanViewport::Present(FVulkanCommandListContext*, FVulkanCmdBuffer*, FVulkanQueue*, FVulkanQueue*, bool)() 0x000000000b0a8080 CitySample!FVulkanCommandListContext::RHIEndDrawingViewport(FRHIViewport*, bool, bool)() 0x000000000b21bcb1 CitySample!FRHICommand<FRHICommandEndDrawingViewport, FRHICommandEndDrawingViewportString2071>::ExecuteAndDestruct(FRHICommandListBase&, FRHICommandListDebugContext&)() 0x000000000b1d6c5e CitySample!FRHICommandListBase::Execute(TRHIPipelineArray<IRHIComputeContext*>&, FRHICommandListBase::FPersistentState::FGPUStats*)() 0x000000000b233c1e CitySample!UE::Core::Private::Function::TFunctionRefCaller<FRHICommandListImmediate::ExecuteAndReset()::$_124, void ()>::Call(void*)() 0x00000000055913aa CitySample!TGraphTask<TFunctionGraphTaskImpl<void (), (ESubsequentsMode::Type)0> >::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type, bool)() 0x0000000007ca4185 CitySample!FNamedTaskThread::ProcessTasksNamedThread(int, bool)() 0x0000000007ca27e0 CitySample!FNamedTaskThread::ProcessTasksUntilQuit(int)() 0x0000000007ca16d9 CitySample!FTaskGraphCompatibilityImplementation::ProcessThreadUntilRequestReturn(ENamedThreads::Type)() 0x000000000b31401c CitySample!FRHIThread::Run()() 0x0000000007db39a6 CitySample!FRunnableThreadPThread::Run()() 0x0000000007d381a8 CitySample!FRunnableThreadPThread::_ThreadProc(void*)() 0x00007965a3c94ac3 libc.so.6!UnknownFunction(0x94ac2) 0x00007965a3d268c0 libc.so.6!UnknownFunction(0x1268bf) [2025.10.11-12.13.49:200][ 29]LogExit: Executing StaticShutdownAfterError Malloc Size=131160 LargeMemoryPoolOffset=393352 Malloc Size=131160 LargeMemoryPoolOffset=524536 Malloc Size=792707 LargeMemoryPoolOffset=1317267 LogPakFile: Display: Found Pak file ../../../Engine/Programs/CrashReportClient/Content/Paks/CrashReportClient.pak attempting to mount. LogPakFile: Display: Mounting pak file ../../../Engine/Programs/CrashReportClient/Content/Paks/CrashReportClient.pak. LogPakFile: Display: Mounted Pak file '../../../Engine/Programs/CrashReportClient/Content/Paks/CrashReportClient.pak', mount point: '../../../Engine/' LogICUInternationalization: ICU TimeZone Detection - Raw Offset: +8:00, Platform Override: '' LogInit: ExecutableName: CrashReportClient LogInit: Build: ++UE5+Release-5.2-CL-26001984 LogInit: Engine Version: 5.2.1-26001984+++UE5+Release-5.2 LogInit: Compatible Engine Version: 5.2.0-25360045+++UE5+Release-5.2 LogInit: Net CL: 25360045 LogInit: OS: Ubuntu 22.04.5 LTS (6.8.0-85-generic), CPU: 12th Gen Intel(R) Core(TM) i9-12900K, GPU: NVIDIA GeForce RTX 4090 (NVIDIA UNIX x86_64 Kernel Module 580.65.06 Sun Jul 27 07:14:19 UTC 2025) LogInit: Compiled (64-bit): Jun 15 2023 05:00:12 LogInit: Architecture: x64 LogInit: Compiled with Clang: 15.0.1 (https://github.com/llvm/llvm-project b73d2c8c720a8c8e6e73b11be4e27afa6cb75bdf) LogInit: Build Configuration: Shipping LogInit: Branch Name: ++UE5+Release-5.2 LogInit: Command Line: -Abslog="/media/lxng/jixie/OpenFly-Platform/envs/ue/env_ue_bigcity/City_UE52/Saved/Logs/City_UE52-CRC.log" "/media/lxng/jixie/OpenFly-Platform/envs/ue/env_ue_bigcity/City_UE52/Saved/Crashes/crashinfo-City_UE52-pid-25976-C08B43F9B4B5419E88A5F06F0905ED43/" LogInit: Base Directory: /media/lxng/jixie/OpenFly-Platform/envs/ue/env_ue_bigcity/Engine/Binaries/Linux/ LogInit: Allocator: Mimalloc LogInit: Installed Engine Build: 1 LogInit: Presizing for max 100000 objects, including 0 objects not considered by GC, pre-allocating 0 bytes for permanent pool. LogInit: Object subsystem initialized [2025.10.11-12.13.49:251][ 0]LogConfig: Applying CVar settings from Section [ConsoleVariables] File [Engine] [2025.10.11-12.13.49:251][ 0]LogInit: Unix hardware info: [2025.10.11-12.13.49:251][ 0]LogInit: - we are the first instance of this executable [2025.10.11-12.13.49:251][ 0]LogInit: - this process' id (pid) is 26143, parent process' id (ppid) is 25976 [2025.10.11-12.13.49:251][ 0]LogInit: - we are not running under debugger [2025.10.11-12.13.49:251][ 0]LogInit: - machine network name is 'lxng-MS-7D31' [2025.10.11-12.13.49:251][ 0]LogInit: - user name is 'lxng' (lxng) [2025.10.11-12.13.49:251][ 0]LogInit: - we're logged in locally [2025.10.11-12.13.49:251][ 0]LogInit: - we're running with rendering [2025.10.11-12.13.49:251][ 0]LogInit: - CPU: GenuineIntel '12th Gen Intel(R) Core(TM) i9-12900K' (signature: 0x90672) [2025.10.11-12.13.49:251][ 0]LogInit: - Number of physical cores available for the process: 16 [2025.10.11-12.13.49:251][ 0]LogInit: - Number of logical cores available for the process: 24 [2025.10.11-12.13.49:251][ 0]LogInit: - GPU Brand Info: NVIDIA GeForce RTX 4090 (NVIDIA UNIX x86_64 Kernel Module 580.65.06 Sun Jul 27 07:14:19 UTC 2025) [2025.10.11-12.13.49:251][ 0]LogInit: - Memory allocator used: Mimalloc [2025.10.11-12.13.49:251][ 0]LogInit: - This binary is optimized with LTO: no, PGO: no, instrumented for PGO data collection: no [2025.10.11-12.13.49:251][ 0]LogInit: - This is an internal build. [2025.10.11-12.13.49:251][ 0]LogCore: Skipped benchmarking clocks because the engine is running in a standalone program mode - CLOCK_MONOTONIC will be used. [2025.10.11-12.13.49:251][ 0]LogInit: Unix-specific commandline switches: [2025.10.11-12.13.49:251][ 0]LogInit: -ansimalloc - use malloc()/free() from libc (useful for tools like valgrind and electric fence) [2025.10.11-12.13.49:251][ 0]LogInit: -jemalloc - use jemalloc for all memory allocation [2025.10.11-12.13.49:251][ 0]LogInit: -binnedmalloc - use binned malloc for all memory allocation [2025.10.11-12.13.49:251][ 0]LogInit: -filemapcachesize=NUMBER - set the size for case-sensitive file mapping cache [2025.10.11-12.13.49:251][ 0]LogInit: -useksm - uses kernel same-page mapping (KSM) for mapped memory (OFF) [2025.10.11-12.13.49:251][ 0]LogInit: -ksmmergeall - marks all mmap'd memory pages suitable for KSM (OFF) [2025.10.11-12.13.49:251][ 0]LogInit: -preloadmodulesymbols - Loads the main module symbols file into memory (OFF) [2025.10.11-12.13.49:251][ 0]LogInit: -sigdfl=SIGNAL - Allows a specific signal to be set to its default handler rather then ignoring the signal [2025.10.11-12.13.49:251][ 0]LogInit: -crashhandlerstacksize - Allows setting crash handler stack sizes (204800) [2025.10.11-12.13.49:251][ 0]LogInit: -noexclusivelockonwrite - disables marking files created by the engine as exclusive locked while the engine has them opened [2025.10.11-12.13.49:251][ 0]LogInit: -httpproxy=ADDRESS:PORT - redirects HTTP requests to a proxy (only supported if compiled with libcurl) [2025.10.11-12.13.49:251][ 0]LogInit: -reuseconn - allow libcurl to reuse HTTP connections (only matters if compiled with libcurl) [2025.10.11-12.13.49:251][ 0]LogInit: -virtmemkb=NUMBER - sets process virtual memory (address space) limit (overrides VirtualMemoryLimitInKB value from .ini) [2025.10.11-12.13.49:251][ 0]LogInit: -allowsyscallfilterfile=PATH_TO_FILE - sets up a system call filter allow list. any invalid syscall in this list *will* cause a crash [2025.10.11-12.13.49:251][ 0]LogInit: - Physical RAM available (not considering process quota): 63 GB (64086 MB, 65624688 KB, 67199680512 bytes) [2025.10.11-12.13.49:251][ 0]LogInit: - VirtualMemoryAllocator pools will grow at scale 1.4 [2025.10.11-12.13.49:251][ 0]LogInit: - MemoryRangeDecommit() will be a no-op (re-run with -vmapoolevict to change) [2025.10.11-12.13.49:251][ 0]LogInit: - PageSize 4096 [2025.10.11-12.13.49:251][ 0]LogInit: - BinnedPageSize 65536 [2025.10.11-12.13.49:252][ 0]LogUObjectArray: 427 objects as part of root set at end of initial load. [2025.10.11-12.13.49:252][ 0]LogUObjectAllocator: 89672 out of 0 bytes used by permanent object pool. [2025.10.11-12.13.49:252][ 0]LogUObjectArray: CloseDisregardForGC: 0/0 objects in disregard for GC pool [2025.10.11-12.13.49:252][ 0]LogPaths: Warning: No paths for game localization data were specifed in the game configuration. [2025.10.11-12.13.49:252][ 0]LogInit: Using OS detected language (zh-CN). [2025.10.11-12.13.49:252][ 0]LogInit: Using OS detected locale (zh-CN). [2025.10.11-12.13.49:252][ 0]LogInit: Warning: No paths for engine localization data were specifed in the engine configuration. [2025.10.11-12.13.49:252][ 0]LogTextLocalizationManager: No localization for 'zh-CN' exists, so 'en' will be used for the language. [2025.10.11-12.13.49:252][ 0]LogTextLocalizationManager: No localization for 'zh-CN' exists, so 'en' will be used for the locale. [2025.10.11-12.13.49:252][ 0]LogInit: Using OS detected language (zh-CN). [2025.10.11-12.13.49:252][ 0]LogInit: Using OS detected locale (zh-CN). [2025.10.11-12.13.49:252][ 0]LogTextLocalizationManager: No localization for 'zh-CN' exists, so 'en' will be used for the language. [2025.10.11-12.13.49:252][ 0]LogTextLocalizationManager: No localization for 'zh-CN' exists, so 'en' will be used for the locale. [2025.10.11-12.13.49:253][ 0]LogPackageLocalizationCache: Processed 2 localized package path(s) for 1 prioritized culture(s) in 0.000164 seconds [2025.10.11-12.13.49:253][ 0]CrashReportCoreLog: CrashReportClientVersion=1.0 [2025.10.11-12.13.49:253][ 0]CrashReportCoreLog: CrashReportReceiver disabled [2025.10.11-12.13.49:253][ 0]CrashReportCoreLog: DataRouterUrl: https://datarouter.ol.epicgames.com/datarouter/api/v1/public/data [2025.10.11-12.13.49:257][ 0]LogInit: Using libcurl 7.83.1 [2025.10.11-12.13.49:257][ 0]LogInit: - built for Linux [2025.10.11-12.13.49:257][ 0]LogInit: - supports SSL with OpenSSL/1.1.1n [2025.10.11-12.13.49:257][ 0]LogInit: - supports HTTP deflate (compression) using libz 1.2.12 [2025.10.11-12.13.49:257][ 0]LogInit: - other features: [2025.10.11-12.13.49:257][ 0]LogInit: CURL_VERSION_SSL [2025.10.11-12.13.49:257][ 0]LogInit: CURL_VERSION_LIBZ [2025.10.11-12.13.49:257][ 0]LogInit: CURL_VERSION_IPV6 [2025.10.11-12.13.49:257][ 0]LogInit: CURL_VERSION_ASYNCHDNS [2025.10.11-12.13.49:257][ 0]LogInit: CURL_VERSION_LARGEFILE [2025.10.11-12.13.49:257][ 0]LogInit: CurlRequestOptions (configurable via config and command line): [2025.10.11-12.13.49:257][ 0]LogInit: - bVerifyPeer = false - Libcurl will NOT verify peer certificate [2025.10.11-12.13.49:257][ 0]LogInit: - bUseHttpProxy = false - Libcurl will NOT use HTTP proxy [2025.10.11-12.13.49:257][ 0]LogInit: - bDontReuseConnections = false - Libcurl will reuse connections [2025.10.11-12.13.49:257][ 0]LogInit: - MaxHostConnections = 16 - Libcurl will limit the number of connections to a host [2025.10.11-12.13.49:257][ 0]LogInit: - LocalHostAddr = Default [2025.10.11-12.13.49:257][ 0]LogInit: - BufferSize = 65536 [2025.10.11-12.13.49:257][ 0]LogAnalytics: Display: [CrashReporter.Release] APIServer = https://datarouter.ol.epicgames.com/. AppVersion = ++UE5+Release-5.2-CL-26001984 [2025.10.11-12.13.49:257][ 0]LogInit: Initializing SDL. [2025.10.11-12.13.49:271][ 0]LogInit: Initialized SDL 2.24.0 revision: (compiled against 2.24.0) [2025.10.11-12.13.49:271][ 0]LogInit: Using SDL video driver 'x11' [2025.10.11-12.13.49:273][ 0]LogSlate: New Slate User Created. Platform User Id 0, User Index 0, Is Virtual User: 0 [2025.10.11-12.13.49:273][ 0]LogSlate: Slate User Registered. User Index 0, Is Virtual User: 0 [2025.10.11-12.13.49:273][ 0]LogSlate: Using FreeType 2.10.0 [2025.10.11-12.13.49:274][ 0]LogSlate: SlateFontServices - WITH_FREETYPE: 1, WITH_HARFBUZZ: 1 [2025.10.11-12.13.49:274][ 0]LogInit: Using SDL_WINDOW_OPENGL [2025.10.11-12.13.49:294][ 0]LogInit: FSlateOpenGLContext::Initialize - creating OpenGL 2.1 context [2025.10.11-12.13.49:316][ 0]CrashReportCoreLog: Initial state = Unknown UploadState value [2025.10.11-12.13.49:316][ 0]CrashReportCoreLog: Initial state = Unknown UploadState value [2025.10.11-12.13.49:317][ 0]LogLinux: Could not get DPI information for monitor #0, assuming 1.0f [2025.10.11-12.13.49:317][ 0]LogLinux: Could not get DPI information for monitor #0, assuming 1.0f [2025.10.11-12.13.49:318][ 0]LogInit: FSlateOpenGLContext::Initialize - creating OpenGL 2.1 context [2025.10.11-12.13.49:320][ 0]LogSlate: Took 0.000510 seconds to synchronously load lazily loaded font '../../../Engine/Content/Slate/Fonts/Roboto-Regular.ttf' (155K) [2025.10.11-12.13.49:321][ 0]LogSlate: Took 0.000544 seconds to synchronously load lazily loaded font '../../../Engine/Content/Slate/Fonts/Roboto-Bold.ttf' (160K) [2025.10.11-12.13.49:322][ 0]LogSlate: Took 0.000511 seconds to synchronously load lazily loaded font '../../../Engine/Content/Slate/Fonts/Roboto-Italic.ttf' (157K)
10-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值