利用贪心法和并查集思想可以获得一个更高效的带期限的作业调度算法-快速作业调度算法 JFS。利用该算法求解下面的带期限的作业调度问题。n=7,期限值为:(d1…d7)=(2,4,1,1,3,4,2) 对应的效益值为(p1…p7)=(30,25,23,18,15,10,9)。
时间: 2023-08-01 16:12:47 浏览: 96
首先按照期限值从小到大排序,得到序列 (3,4,1,7,2,5,6)。然后对于每个作业,从它的期限值往前找到第一个空闲的时间槽,将该作业安排在该时间槽上。如果找不到空闲的时间槽,则该作业无法完成。最后计算完成作业的效益之和即可。
具体实现过程如下:
1. 按照期限值从小到大排序,得到序列 (3,4,1,7,2,5,6)。
2. 初始化一个并查集,表示每个时间槽的占用情况。
3. 遍历每个作业,对于作业 i,从它的期限值往前找到第一个空闲的时间槽 j,如果时间槽 j 不存在,则说明该作业无法完成,跳过该作业。否则,将作业 i 安排在时间槽 j 上,同时将时间槽 j 的占用情况合并到时间槽 j-1 上。
4. 遍历完成后,计算完成作业的效益之和。
代码实现如下:
相关问题
利用css给我做一个京东超市侧边栏页面出来
好的,以下是一个简单的京东超市侧边栏页面的示例代码:
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>京东超市侧边栏</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="sidebar">
<ul class="menu">
<li class="active"><a href="#">全部商品</a></li>
<li><a href="#">饮料冲调</a></li>
<li><a href="#">乳品糕点</a></li>
<li><a href="#">休闲零食</a></li>
<li><a href="#">粮油调味</a></li>
<li><a href="#">生鲜果蔬</a></li>
<li><a href="#">家居清洁</a></li>
<li><a href="#">个人护理</a></li>
<li><a href="#">母婴用品</a></li>
<li><a href="#">进口商品</a></li>
</ul>
<div class="ad">
<img src="https://img12.360buyimg.com/n1/jfs/t1/154969/18/15866/148669/60c9c2d6Eb3c80cb2/fd1b1e8d4c7f2a7c.jpg">
</div>
</div>
</body>
</html>
```
CSS代码:
```css
/* 重置默认样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 侧边栏样式 */
.sidebar {
position: fixed;
top: 50%;
left: 0;
transform: translateY(-50%);
background-color: #fff;
border-right: 1px solid #dcdcdc; /* 添加右边框 */
width: 200px;
height: 400px;
}
/* 菜单样式 */
.menu {
list-style: none;
margin: 20px 0;
padding: 0;
}
.menu li {
margin-bottom: 10px;
}
.menu li a {
display: block;
padding: 10px;
color: #333;
text-decoration: none;
}
.menu li.active a {
background-color: #f5f5f5;
}
.menu li:hover a {
background-color: #f5f5f5;
}
/* 广告样式 */
.ad img {
width: 100%;
height: auto;
}
```
你可以将代码复制到一个HTML文件中,并将CSS代码保存到一个名为`style.css`的文件中,然后在浏览器中打开HTML文件查看结果即可。
用html5和css3做一个京东商品页面
好的,下面是一个简单的京东商品页面示例,仅供参考:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>京东商品页面</title>
<style>
/* Reset styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* General styles */
body {
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 1.5;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
h1 {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
.product {
display: flex;
flex-wrap: wrap;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 5px;
overflow: hidden;
}
.product-image {
flex: 0 0 50%;
max-width: 50%;
height: 400px;
background-image: url('https://img14.360buyimg.com/n1/s450x450_jfs/t1/168625/28/10522/287243/606f7f08E9d27a6f7/4e478b12eb9a9e6c.jpg');
background-size: cover;
background-position: center;
}
.product-details {
flex: 1 1 50%;
max-width: 50%;
padding: 20px;
}
.product-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.product-price {
font-size: 24px;
color: #c00;
margin-bottom: 20px;
}
.product-description {
font-size: 14px;
line-height: 1.5;
margin-bottom: 20px;
}
.product-features {
font-size: 14px;
line-height: 1.5;
margin-bottom: 20px;
}
.product-add-to-cart {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.product-add-to-cart label {
font-size: 14px;
margin-right: 10px;
}
.product-add-to-cart input[type='number'] {
width: 50px;
height: 30px;
border: 1px solid #ddd;
border-radius: 3px;
padding: 5px;
}
.product-add-to-cart button {
background-color: #c00;
color: #fff;
border: none;
border-radius: 3px;
padding: 10px 20px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>京东商品页面</h1>
<div class="product">
<div class="product-image"></div>
<div class="product-details">
<div class="product-title">小米手环6NFC</div>
<div class="product-price">¥229</div>
<div class="product-description">小米手环6NFC,智能健康小助手,支持NFC智能支付,全新AMOLED屏幕,更清晰、更灵敏,全天候健康监测,每天更好的健康习惯,超长续航,7天待机</div>
<div class="product-features">
<ul>
<li>全新AMOLED屏幕,更清晰、更灵敏</li>
<li>支持NFC智能支付</li>
<li>全天候健康监测</li>
<li>超长续航,7天待机</li>
</ul>
</div>
<div class="product-add-to-cart">
<label for="quantity">数量:</label>
<input type="number" id="quantity" name="quantity" min="1" max="10" value="1">
<button>加入购物车</button>
</div>
</div>
</div>
</div>
</body>
</html>
```
在浏览器中打开该 HTML 文件,就可以看到一个简单的京东商品页面了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)