一、预备知识—程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其 操作方式类似于数据结构中的栈。 2、堆区(heap) — 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回 收 。...
分类:
编程语言 时间:
2015-08-15 01:24:15
阅读次数:
145
上一节中介绍了mutex的基本使用方法,使用mutex来保护共享数据并不能解决race condition带来的问题,假如我们有一个堆栈数据结构类似于std::stack它提供了5个基本操作push(),pop(),top(),empty(),和size()。这里的top()操作返回栈顶元素的拷贝,这样我们就可以使用一个mutex来保护栈内部的数据。但是race codition情况下,虽然使用m...
分类:
编程语言 时间:
2015-08-14 22:47:55
阅读次数:
155
题意:n*m的格子,中间有若干点不能走,问从左上角到右下角有多少种走法。思路:CountWay(i,j) 表示从 i 点到 j 点的种数。然后用容斥原理加加减减解决 1 #pragma comment(linker, "/STACK:1000000000") 2 #include 3 #inclu....
分类:
其他好文 时间:
2015-08-14 13:19:02
阅读次数:
118
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280源点是West, 汇点是East, 用Dinic带入求就好了代码:要用c++提交#pragma comment(linker, "/STACK:102400000,102400000") ///手动开....
分类:
其他好文 时间:
2015-08-14 11:17:45
阅读次数:
108
形如hdu 5381:点击打开链接
add(int x, int y)的函数复杂度为 O(|x-y|)
del同理
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include
#include
#include
#include
#include
#include
#include ...
分类:
编程语言 时间:
2015-08-14 01:07:13
阅读次数:
223
Implement the following operations of a stack using queues.
push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet...
分类:
其他好文 时间:
2015-08-13 22:21:08
阅读次数:
162
题意:问小于n且不与n互质的数的和是多少。容斥原理求出和n互质的和,然后用 n*(n-1)/2 减以下,注意溢出。#pragma comment(linker,"/STACK:102400000,102400000") #define _CRT_SECURE_NO_WARNINGS#include#...
分类:
其他好文 时间:
2015-08-13 21:52:05
阅读次数:
155
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
java.util.Vector
java.util.Stack
Stack类的继承关系如上,其直接继承自Vector,Vector可以作为一个集合使用。Stack在其上完成了“后进先出”的功能。Stack实...
分类:
其他好文 时间:
2015-08-13 15:56:10
阅读次数:
166
自己实现的简单的Stack,没有查空满,用于算法考试
#include
using namespace std;
const int MAX = 100;
struct MyStack
{
int data[MAX];
int top;
}stack={{0},0};
int main()
{
for(int i = 0;i<10;i++)
{
stack.data[s...
分类:
其他好文 时间:
2015-08-13 15:48:29
阅读次数:
96
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get...
分类:
其他好文 时间:
2015-08-13 15:48:22
阅读次数:
97