mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-10 19:10:57 +00:00
feat(csharp) .NET 8.0 code migration (#966)
* .net 8.0 migration * update docs * revert change * revert change and update appendix docs * remove static * Update binary_search_insertion.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -7,19 +7,14 @@
|
||||
namespace hello_algo.chapter_greedy;
|
||||
|
||||
/* 物品 */
|
||||
class Item {
|
||||
public int w; // 物品重量
|
||||
public int v; // 物品价值
|
||||
|
||||
public Item(int w, int v) {
|
||||
this.w = w;
|
||||
this.v = v;
|
||||
}
|
||||
class Item(int w, int v) {
|
||||
public int w = w; // 物品重量
|
||||
public int v = v; // 物品价值
|
||||
}
|
||||
|
||||
public class fractional_knapsack {
|
||||
/* 分数背包:贪心 */
|
||||
public double FractionalKnapsack(int[] wgt, int[] val, int cap) {
|
||||
double FractionalKnapsack(int[] wgt, int[] val, int cap) {
|
||||
// 创建物品列表,包含两个属性:重量、价值
|
||||
Item[] items = new Item[wgt.Length];
|
||||
for (int i = 0; i < wgt.Length; i++) {
|
||||
@@ -46,8 +41,8 @@ public class fractional_knapsack {
|
||||
|
||||
[Test]
|
||||
public void Test() {
|
||||
int[] wgt = { 10, 20, 30, 40, 50 };
|
||||
int[] val = { 50, 120, 150, 210, 240 };
|
||||
int[] wgt = [10, 20, 30, 40, 50];
|
||||
int[] val = [50, 120, 150, 210, 240];
|
||||
int cap = 50;
|
||||
|
||||
// 贪心算法
|
||||
|
||||
Reference in New Issue
Block a user