Ch3-3: popat(int idx) of setofstack

医学图像处理(一)使用U-Net进行MRI的肝脏分割 医学图像处理(一)使用U-Net进行MRI的肝脏分割数据集搜集训练集和测试集划分问题一: 测试集不包括GroundTruth问题二:T1和T2的数据能一起训练吗?问题三: T1的图像在文件夹中分成了InPhase和OutPhase,这个有什么区别?分离出肝脏将dicom文件转换为png格式数据增强U-net网络搭建自定义DatasetMain.py实验结果总结 图像分割小白一枚,之前接到一个MRI图像肝脏分割的任务。对于医学图像分割,第一想到的就是Unet. Unet在2015的MICCAI上首次提出,在医 阅读详情

Continue to use class to design solution, also, start to use STL, such as container (vector, stack, set, ...). save time and to be more professional.

The design without popat method is similar to the one to devide a single array into 3 stacks. 

But the class of setofstack with popat should be more carefully.


for example: 

bool empty(){  // empty of the whole set
		//if(cur==0) return st[cur].empty();
            // this is not working because it might have 
            // blank substack in the middle of full stack
            // so need to have while condition to find the last 
            // not-empty stack
        // if (cur!=-1 && st[cur].empty()) --cur; --->
            // this one only find the previous stack of 
            // empty stack, need to use while condition instead
		while(cur!=-1 && st[cur].empty()) --cur;
		if (cur==-1) return true;
		return false;
	}



Full code.  Still, this is modified from Hawstein's code but may not the best solution, learn from others too..

// solution to Ch 3-3
// Ch3-3: popAt(int idx) should be careful in designing the 
// corner conditions, such as the empty method of setofstack
// (with popat, due to the condition of empty substack in 
// middle, need to use while condition instead of if condition)
//

#include 
using namespace std;

const int STACK_SIZE = 10;
const int STACK_NUM = 5;

class stack{
public:
    stack(int size=STACK_SIZE){
        buf = new int[size];
		ptop = -1;
		this->capacity = size;
	}

	~stack(){
		delete[] buf;
	}

	void push(int val){
		buf[++ptop] = val;
        //cout << "push" << endl;
	}

	void pop(){
		--ptop;
        //cout << "pop" << endl;
	}

	int top(){
		return buf[ptop];
        cout << "T" << endl;
	}

	bool empty(){
		return ptop==-1;
        cout << "E" << endl;
	}

	bool full(){
		return ptop==capacity-1;
	    cout << "F" << endl;
    }

private:
	int* buf;
	int ptop;
	int capacity;
};

class SetOfStacks{//without popAt()
public:
	SetOfStacks(int size = STACK_NUM){
		st = new stack[size];
		cur = 0;
		this->capacity = size;
	}	

	~SetOfStacks(){
		delete[] st;
	}

	void push(int val){
		if(st[cur].full()) ++cur;
		st[cur].push(val);
	}

	void pop(){
		if(st[cur].empty()) --cur;
		st[cur].pop();
	}

	int top(){
		if(st[cur].empty()) --cur;
		return st[cur].top();
	}

	bool empty(){  // empty of the whole set
		if(cur==0) return st[cur].empty();
		return false;
	}

	bool full(){
		if(cur==capacity-1) return st[cur].full();
		return false;
	}

private:
	stack *st;
	int cur;
	int capacity;
};

class SetOfStacks1{//with popAt()
public:
	SetOfStacks1(int size = STACK_NUM){
		st = new stack[size];
		cur = 0;
		this->capacity = size;
	}	

	~SetOfStacks1(){
		delete[] st;
	}

	void push(int val){
		if(st[cur].full()) ++cur;
		st[cur].push(val);
	}

	void pop(){
		while(st[cur].empty()) --cur;
		st[cur].pop();
	}
/*
	void popAt(int idx){ // should not pop if that stack is empty
		if(~st[idx].empty()) cout << "no popat" <
            // this one only find the previous stack of 
            // empty stack, need to use while condition instead
		while(cur!=-1 && st[cur].empty()) --cur;
		if (cur==-1) return true;
		return false;
	}

	bool full(){
		if(cur==capacity-1) return st[cur].full();
		return false;
	}

private:
	stack *st;
	int cur;
	int capacity;
};

int main(){
#if 0
     SetOfStacks ss0;
     for(int i=0; i

output:

Executing the program....
$demo 
19
18
17
16
15
14
13
12
11
10
huxiaolin ...TOT


Transformers在自动驾驶领域的应用(High-level like in scene) Transformers uses global attention mechanism to capture long-range interaction information. Two core modules in Transformers are Self-Attention and Cross-Attention, which defined asAttn(Q,K,V)=softmax(QK⊤dk)VSelfAttn(X)=Attn(WQX,WKX,WVX)CrossAttn(X,Y)=Attn 阅读详情

相关推荐

(MIUI)小米手机录音文件深度寻踪:从系统缓存到数据目录的实战解析

本文深入解析了MIUI系统中录音文件丢失的常见原因及解决方案,包括系统升级兼容性问题、应用缓存机制异常和存储权限变动。通过实战操作指南,详细介绍了如何从系统目录、数据库层面恢复录音文件,并提供了预防措施和自动化备份方案,帮助小米手机用户有效找回重要录音数据。

weixin_42699679的博客 520

C语言可变参数详解

1.什么是可变参数 在C语言编程中有时会遇到一些参数可变的函数,例如printf()、scanf(),其函数原型为: int printf(const char* format,…) int scanf(const char *format,…) 就拿 printf 来说吧,它除了有一个参数 format 固定以外,后面的参数其个数和类型都是可变的,用三个点“…”作为参数占位符。 2.参数列表的构成 任何一个可变参数的函数都可以分为两部分:固定参数和可选参数。至少要有一个固定参数,其声明与普通函

C/C++、嵌入式开发、深度学习算法、模型部署与推理优化 7852

2021英伟达暑期实习面经(芯片设计)

2021英伟达暑期实习面经(芯片设计前端/DFT) 准备了将近一个月,终于赶在三月的最后一天拿到了offer,暑期实习算是上岸了,后面还有阿里/华为等一些国内公司的面试,但既然拿到了nv的offer,后面的先就当积累面试经验吧~ 网上关于nv的实习or秋招面经很少,硬件岗的更少(约等于没有好吧)。之前准备面试的时候,在网上找了半天,好像就只在牛客网上见过一篇关于nv硬件岗的面经,幸好当时认真看了哈哈。所以既然幸运上岸了,想趁自己还记得,record一下,希望可以帮到有缘人呀~ 好了,废话不多说,开始正题。

Hadleysjtu的博客 1万+

数据结构(一)

链表 模拟栈 模拟队列 单调栈 单调队列 kmp

qq_41320429的博客 367

STM32 SAI接口TDM模式实战:8通道音频采集系统搭建全流程(附DMA配置代码)

本文详细介绍了基于STM32 SAI接口TDM模式搭建8通道音频采集系统的全流程。内容涵盖硬件连接设计、CubeMX时钟树与SAI外设的详细配置,并重点解析了TDM模式的核心代码实现与DMA双缓冲机制,提供了完整的配置代码和常见时序问题排查指南,助力开发者高效实现多通道音频传输与处理。

weixin_29192211的博客 507

EV1527 vs HS1527:固定码芯片的STM32解码避坑指南

本文深入解析EV1527与HS1527固定码芯片的技术差异,提供基于STM32的完整解码方案与稳定性优化策略。通过硬件接口配置、状态机实现及示波器诊断,解决工业遥控、安防报警等场景中的解码难题,特别针对时序差异和干扰问题给出实用解决方案。

o0p1q2r3的博客 334

SnpSift学习笔记(二)

欢迎关注&#34;生信修炼手册&#34;!本篇主要介绍interval, intidx, split, extractFields这四个命令。1. intervalsintervals命...

庐州月光的博客 1155

Palantir的Ontology:从静态知识图谱到动态业务引擎的跃迁

本文探讨了Palantir的Ontology技术如何将静态知识图谱升级为动态业务引擎。通过引入函数和行动作为核心元素,Ontology实现了业务逻辑的自动化响应与执行,显著提升物流、能源等领域的运营效率。文章详细解析了其混合存储引擎、状态监听网络等关键技术设计,并对比展示了传统架构与Ontology架构的业务价值差异。

weixin_42570296的博客 203

单链表(数组模拟:静态链表)

单链表 实现一个单链表,链表初始为空,支持三种操作: 向链表头插入一个数; 删除第 kk 个插入的数后面的数; 在第 kk 个插入的数后插入一个数。 现在要对该链表进行 MM 次操作,进行完所有操作后,从头到尾输出整个链表。 注意:题目中第 kk 个插入的数并不是指当前链表的第 kk 个数。例如操作过程中一共插入了 nn 个数,则按照插入的时间顺序,这 nn 个数依次为:第 11 个插入的数,第 22 个插入的数,…第 nn 个插入的数。 输入格式 第一行包含整数 MM,表示操作次数。 接下来 MM 行

weixin_52621900的博客 802

基于单片机负载控制的无人机电气设备监测系统设计

为深入分析无人机电气设备的电子负载性能,实现对传输电子量的合理性监管与控制,设计基于单片机负载控制的无人机电气设备监测系统;利用电气信号发生电路,构建负载网络控制器与以太网模块运行所需的电气设备负载环境,借助PCB监控板建立PLC扩展负载模块与核心监控主机之间的物理连接关系,实现无人机电气设备监测系统的硬件执行环境搭建;在此基础上,通过STM32型单片机移植协议,确定无人机电气设备通信主机的现有组态形式,联合已设定的监控任务有线级条件,实现监测系统的软件执行环境搭建,完成基于单片机负载控制的无人机电气设备监

weixin_45905610的博客 1300

Q&A | ZStack替代VMware实问实答

ZStack替代VMware实问实答

zstack_org的博客 1801

单链表-数据结构

用数组模拟单链表.

qq_63961708的博客 552

【AUTOSAR OS】调度表管理模块深度解析

本文深入解析AUTOSAR OS调度表的实现机制。调度表通过预定义到期点序列控制任务激活时序,支持周期性执行、多核协同和容错处理。核心数据结构包括调度表控制块(STCB)、配置结构和到期点动作。关键函数涵盖初始化、启动、到期点处理及链表管理,采用O(n)时间复杂度。以发动机控制为例展示配置与使用方式,并探讨显式同步、时间容错等高级特性。最后提出EP数量控制、链表优化等性能建议,为汽车ECU时间触发系统开发提供参考。

1607

面试14之请实现一种数据结构SetOfStacks

题目描述 请实现一种数据结构SetOfStacks,由多个栈组成,其中每个栈的大小为size,当前一个栈填满时,新建一个栈。该数据结构应支持与普通栈相同的push和pop操作。 给定一个操作序列int[][2] ope(C++为vector>),每个操作的第一个数代表操作类型,若为1,则为push操作,后一个数为应push的数字;若为2,则为pop操作,后一个数无意义。请返回一个int[][]

hj605635529的博客 810

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

集合栈

题目描述 请实现一种数据结构SetOfStacks,由多个栈组成,其中每个栈的大小为size,当前一个栈填满时,新建一个栈。该数据结构应支持与普通栈相同的push和pop操作。 给定一个操作序列int[][2] ope(C++为vector>),每个操作的第一个数代表操作类型,若为1,则为push操作,后一个数为应push的数字;若为2,则为pop操作,后一个数无意义。请返回一个i

feige1990的专栏 910

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

栈队列例题2:SetOfStack放盘子

代码如下:    1 import java.util.ArrayList; 2 import java.util.Scanner; 3 4 public class SetOfStack { 5 6 public static void main(String[] args) { 7 Scanner sc=ne...

dijizao9635的博客 228

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

数组中第K大元素

数组中第K大元素在面试的时候遇到过这个问题,后来在leetcode上也遇到了这个问题,于是记录下来以便以后快速回忆。题目有多种思路,全排序是比较直观的想法,然而最低的时间复杂度为O(nlgn),并且不符合该题目的初衷。题目更多想问的是如何在不进行全排序的条件下找到数组中第K大的元素,个人认为比较被面试官中意的解答有两个(理应也有其他的..),如下:构建最大堆简单分析时间复杂度: 构建堆的时间O(n)

等价交换 3396

cc150做题计划

计划:12.29.2013 - 1.29.2013 做完第一遍题目,然后2月做leetcode。 2月底面试前完成200题C++。 这里记录一下ctci学习的参考资料。 1. hawstein的blog 2. https://github.com/ChengTian/CtCI 3. absolute C++ 5th 4. Primer C++ 5. learncpp:http

纯黑老白的专栏 2909

ch4.6: find the LCA of 2 nodes in a binary tree with 3 different methods

In this problem, it is important to fully understand the definition of least common ancestor of 2 nodes: it means: (from leetcode blog: 点击打开链接) _______3______ / \

纯黑老白的专栏 1330

Ch1.6: IN-place-ly rotate a pic(NxN matrix) by 90 digree in Verilog(CPP)

这个有点像DSP FPGA Chang Choo的题目,一般是放大插值,DFT,IIR之类的Verilog题目。 题目在这:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees.

纯黑老白的专栏 1295

Ch2-2: return the nth to the last node data of a singly linked list

In this problem, I need to find the nth to the last node data of a singly linked list.  In order to do so, one good way is to use recursion, since it is automatically put recursion part into stack an

纯黑老白的专栏 1290

1/22/2014: 纪念第一个C++ programmer电面--F家

经过20天的CC刷题(其实是学习),才刚刚做到第四章。看看其他非ACM牛人,都是leetcode,CC,EPI滚瓜烂熟才去面。而且onsite确实是靠实力,要有做过大project之后才能真正融会贯通C++精神。 Anyway,谢谢郭志给的refer,不然连电面的机会都没有。 开头是C++基础题: 1. Fib的2种写法:recursive和DP 2. Struct和Class的区别;在C

纯黑老白的专栏 1274

Ch1-7: clear the row i and column j iff a[i][j]==0

in this problem, both monish001 and hawstein use O(n^2) solution which first tranverse the char** a to find the a[i][j]==0 and mark that row/col to be: TRUE. Then the send loop make the TURE row/col

纯黑老白的专栏 1207

复习一下dfs和bfs 用java

dfs 和 bfs都是用来找从source 到 target的path的算法。 dfs用的是recursion,bfs则用queue

纯黑老白的专栏 1191

Ch3-1: use a single array to implement three stacks.

Here it explains why Hawstein use this in his constructor, because he use size a parameter in his constructor while "size" is also a member variable(it's private), so he use this->size = size, explici

纯黑老白的专栏 1097

ch4.7: given 2 huge Binary tree t1, t2(>1millon nodes), decide if one tree is subtree of another one

// Ch4.7: You have two very large binary trees: T1, with millions of nodes, and T2, // with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1 #include #include #includ

纯黑老白的专栏 1030
上一篇: cc150做题计划
下一篇: Ch3-4: solve Hanoi in C++ with recursion, and with stack explicitly
纯黑老白
博客等级 码龄18年 30粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值