Placements(连接)

有三张表students(id, name), friends(id, friend_id),packages(id, salary)

要求输出:

1、输出朋友的工资比自己高的人名

2、按朋友的工资升序

思路:

1、friends与package表连接两次得到 id1, salary(id),salary(friend_id)

2、过滤到salary(friend_id)>salary(id)

3、与students连接

sql为

select students.name as name from
(
select t2.id1 as id1, t2.s1 as s1, t2.s2 as s2 from 
(
select t1.id1 as id1, t1.s1 as s1, p2.salary as s2 from 
(select f1.id as id1, f1.friend_id as id2, p1.salary as s1 from friends as f1 inner join packages p1 on f1.id = p1.id) t1
inner join packages p2 on t1.id2 = p2.id
) 
t2
where t2.s2 > t2.s1
) tmp inner join students on tmp.id1 = students.id
 order by tmp.s2;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个简单的模拟退火算法的板材排版C#代码示例: ```csharp using System; using System.Collections.Generic; using System.Linq; class Sheet { public int Width { get; set; } public int Height { get; set; } } class Piece { public int Width { get; set; } public int Height { get; set; } } class Placement { public Piece Piece { get; set; } public int X { get; set; } public int Y { get; set; } } class Program { static Random random = new Random(); static List<Placement> SimulatedAnnealing(List<Piece> pieces, Sheet sheet, double temperature, double coolingRate) { List<Placement> bestSolution = new List<Placement>(); List<Placement> currentSolution = GenerateRandomSolution(pieces, sheet); while (temperature > 1) { List<Placement> newSolution = GenerateRandomSolution(pieces, sheet); double currentEnergy = CalculateEnergy(currentSolution, sheet); double newEnergy = CalculateEnergy(newSolution, sheet); double deltaEnergy = newEnergy - currentEnergy; if (deltaEnergy < 0 || Math.Exp(-deltaEnergy / temperature) > random.NextDouble()) { currentSolution = newSolution.ToList(); } if (CalculateEnergy(currentSolution, sheet) < CalculateEnergy(bestSolution, sheet)) { bestSolution = currentSolution.ToList(); } temperature *= coolingRate; } return bestSolution; } static List<Placement> GenerateRandomSolution(List<Piece> pieces, Sheet sheet) { List<Placement> placements = new List<Placement>(); foreach (Piece piece in pieces) { int x = random.Next(sheet.Width - piece.Width); int y = random.Next(sheet.Height - piece.Height); placements.Add(new Placement() { Piece = piece, X = x, Y = y }); } return placements; } static double CalculateEnergy(List<Placement> placements, Sheet sheet) { double energy = 0; foreach (Placement placement in placements) { if (placement.X < 0 || placement.Y < 0 || placement.X + placement.Piece.Width > sheet.Width || placement.Y + placement.Piece.Height > sheet.Height) { energy += 1; } foreach (Placement otherPlacement in placements.Where(p => p != placement)) { if (placement.X < otherPlacement.X + otherPlacement.Piece.Width && placement.X + placement.Piece.Width > otherPlacement.X && placement.Y < otherPlacement.Y + otherPlacement.Piece.Height && placement.Y + placement.Piece.Height > otherPlacement.Y) { energy += 1; } } } return energy; } static void Main(string[] args) { List<Piece> pieces = new List<Piece>() { new Piece() { Width = 2, Height = 3 }, new Piece() { Width = 4, Height = 2 }, new Piece() { Width = 3, Height = 3 }, new Piece() { Width = 1, Height = 4 }, new Piece() { Width = 2, Height = 2 }, new Piece() { Width = 3, Height = 1 } }; Sheet sheet = new Sheet() { Width = 10, Height = 10 }; List<Placement> solution = SimulatedAnnealing(pieces, sheet, 100, 0.99); foreach (Placement placement in solution) { Console.WriteLine("Piece ({0}, {1}) placed at ({2}, {3})", placement.Piece.Width, placement.Piece.Height, placement.X, placement.Y); } Console.ReadLine(); } } ``` 该示例中,`Sheet`类表示板材,包含宽度和高度属性;`Piece`类表示零件,包含宽度和高度属性;`Placement`类表示零件的位置,包含零件、X坐标和Y坐标属性。`SimulatedAnnealing`方法使用模拟退火算法生成最佳的零件排版方案,输入参数包括零件列表、板材和退火的初始温度和冷却速率。`GenerateRandomSolution`方法生成随机的零件排版方案,`CalculateEnergy`方法计算给定排版方案的能量(即不良解的程度)。 该示例中使用了一个简单的能量函数,它考虑了每个零件的边界和重叠情况。能量函数的值越小,排版方案越好。模拟退火算法随着时间的推移逐渐减小温度,从而在探索和利用最佳排版方案之间找到平衡。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值