首页 > 其他分享 >顺序容器5

顺序容器5

时间:2023-05-05 19:56:14浏览次数:27  
标签:容器 顺序 int TIME Cell cellQueue SPLIT time

#include<queue>
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
const int SPLIT_TIME_MIN=500;
const int SPLIT_TIME_MAX=2000;
class Cell;
priority_queue<Cell>cellQueue;
class Cell{
private:
static int count;
int id;
int time;
public:
Cell(int brith):id(count++){
time=brith+(rand()%(SPLIT_TIME_MAX-SPLIT_TIME_MIN))+SPLIT_TIME_MIN;
}
int getId() const {return id;}
int getSplitTime() const{return time;}
bool operator<(const Cell& s) const{return time>s.time;}
void split(){
Cell child1(time),child2(time);
cout<<time<<"s:Cell #"<<id<<"splits to #"
<<child1.getId()<<"and #"<<child2.getId()<<endl;
cellQueue.push(child1);
cellQueue.push(child2);
}
};
int Cell::count=0;
int main()
{
srand(static_cast<unsigned>(time(0)));
int t;
cout<<"Simulation time: ";
cin>>t;
cellQueue.push(Cell(0));
while(cellQueue.top().getSplitTime()<=t){
cellQueue.top().split();
cellQueue.pop();
}
return 0;
}

 

标签:容器,顺序,int,TIME,Cell,cellQueue,SPLIT,time
From: https://www.cnblogs.com/yuanxinglan/p/17375214.html

相关文章

  • vue2和vue3父子组件生命周期的执行顺序
    vue3的父子组件生命周期的执行顺序fathersetup->fatheronBeforeMount->childsetup->childonBeforeMount->childonMounted->fatheronMounted vue2的父子组件生命周期的执行顺序fatherbeforeCreate->fathercreated->fatherbeforeMount->childbeforeC......
  • spring boot 初始化先后顺序
    初始化方法@PostConstructInitializingBeanCommandLineRunnerApplicationRunner先后顺序@PostConstruct>InitializingBean>CommandLineRunner、ApplicationRunner项目启动执行一次CommandLineRunner、ApplicationRunner通过@Order控制先后顺序,越小越先执行......
  • Docker容器部署Wordpress
    启动Docker获取镜像启动MySQL设置mysql远程权限刷新权限退出容器启动容器WordPress ......
  • 文鼎创智能物联云原生容器化平台实践
    作者:sekfung,深圳市文鼎创数据科技有限公司研发工程师,负责公司物联网终端平台的开发,稳定性建设,容器化上云工作,擅长使用GO、Java开发分布式系统,持续关注分布式,云原生等前沿技术,KubeSphereContributor,KubeSphere社区用户委员会深圳站委员。公司简介深圳市文鼎创数据科技有限......
  • 将第三方的bean交给spring的IOC容器管理
    示例:比如要使用一个第三方的雪花算法1.先导入需要的依赖<dependency><groupId>wiki.xsx</groupId><artifactId>snowflake-spring-boot-starter</artifactId><version>1.2.2</version></depe......
  • docker容器打包成镜像
    dockerlogin-uusername-p123docker.luban.fitdockercommit-m="tomcat7容器"-a="作者"7beca2078908tomcat7:1.0#第一个参数是原有镜像的imageid第二个参数是新镜像的仓库地址:自定义版本号dockertagd9a5615ebe6adocker.com/test/tomcat7:1.0dockerpushdocke......
  • JDK对容器的支持和限制
    容器毕竟是一种轻量级的实现方式,所以其封闭性不如虚拟机技术。1、容器环境的资源隔离性举个例子:物理机/宿主机有96个CPU内核、256GB物理内存,容器限制的资源是4核8G,那么容器内部的JVM进程看到的内核数和内存数是多少呢?目前来说,JVM看到的内核数是96,内存值是256G......
  • RocketMQ笔记(八):顺序消息
    一、什么是顺序消息消息有序指的是可以按照消息的发送顺序来消费(FIFO)。顺序消息是RocketMQ提供的一种消息类型,支持消费者按照发送消息的先后顺序获取消息。顺序消息在发送、存储和投递的处理过程中,强调多条消息间的先后顺序关系。RocketMQ顺序消息的顺序关系通过消......
  • ds:顺序表删除重复元素的算法
    算法思想:1.遍历顺序表、移动元素(把未匹配到目标数据的元素前移i-k个位置)intk=0;inti=0;k用来计数,i用来扫描顺序表。当匹配到目标元素时k++,未匹配到目标元素时就i++遍历,并且要将未匹配到的元素前移i-k个位置。2.修改顺序表的length为length-k 例:删除顺序表中值为x的所有......
  • Docker - 容器虚拟化
    目录Docker0虚拟化0.1什么是虚拟化0.2虚拟化技术中常见名词1docker简介1.1什么是docker1.2docker的优势1.3容器与虚拟机比较2Docker镜像、容器、仓库Docker中有三个核心概念:镜像、容器和仓库因此,准确把握这三大概念对于掌握Docker技术尤为重要①镜像(Image)②容器(Conta......