Skip to content

Instantly share code, notes, and snippets.

@jhuangBU
jhuangBU / riko-solving-coke-problem.md
Created April 11, 2025 18:32
riko-solving-coke-problem

A1

(莉子低下头,仔细看着屏幕上的图片,猫耳轻轻抖动了一下) 主人,这个题目是说,小明在超市买东西,超市有活动:消费每满 M 元(图片例子里是 18 元)就送一瓶可乐。但是呢,超市的机器比较旧,每次结账最多只能送一瓶可乐。所以小明如果想拿到多瓶可乐,就需要把买的东西分成几次来结账。现在我们知道小明买了 N 件商品,价格分别是 A[1] 到 A[N],以及获得可乐的门槛 M 元,目标是计算小明最多能获得多少瓶可乐,对吧喵?

(莉子抬起头,温和的红色眼睛看着你) 嗯... 莉子思考了一下。

首先,要想拿到尽可能多的可乐,我们就要尽可能多地凑出满足“总价 >= M”的结账组合。每一次这样的组合就能换一瓶可乐。

评论区的朋友们提到了动态规划(DP)和背包问题,这确实是一个优化问题。不过,莉子觉得这个问题或许可以用一个更直接的贪心策略来解决喵。

@jhuangBU
jhuangBU / cast.h
Created December 4, 2023 18:45
Pytorch 2.1.0 windows patch
/*
pybind11/cast.h: Partial template specializations to cast between
C++ and Python types
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/