模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; struct node *q; struct node *h; }node; struct Node { node *start; node *end; int sum; }m[]; int main() { int k; scanf("%d", &k); while (k--) { i…
题意: 第一类物品的价值为k1,第二类物品价值为k2,背包的体积是 c ,第一类物品有n 个,每个体积为S11,S12,S13,S14.....S1n ; 第二类物品有 m 个,每个体积为 S21,S22,S23,S24.......S2m; 每次装入物品时,得到的价值是 剩余背包体积*该类物品的价值:问最多能得到的总价值是多少. 思路: 要想得到最大的总价值,肯定要从小的开始装,然后分别枚举第一类,第二类装进去的最大体积,还有将两类回合装入背包的最大体积,得到最后的答案 我们用dp[i][j]…
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示状态.当所在格子为0时只能上下移动,为1时左右移动.人一秒动一次,并且每一秒必须移动,灯每秒改变依次状态.问从起点到终点最短时间. 题解:   就看成一道墙壁会按时间周期改变的走迷宫. 只是墙壁的作用是限制走的方向而不是不能通过. 关于如何判定迷宫无法走通,按套路设了一个vis数组,试了一发就ac了…
题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意自己翻译,此题首先肯定是要广搜的,不过要开一个1e5*1e5的数组好像有点困难, 所以用结构体来存每个点的下标,然后从源点开始广搜.定义一个pair<node,int>,第一个存节点信息,第二个存到当前节点的步数,因为还要处理到达每个节点的状态. 状态:走奇数步并且状态为1与走偶数步状态为0的结果…
Pretty Matrix Time Limit: 1 Second      Memory Limit: 65536 KB DreamGrid's birthday is coming. As his best friend, BaoBao is going to prepare a gift for him. As we all know, BaoBao has a lot of matrices. This time he picks an integer matrix with  row…
题意:模拟栈,正常pop,push,多一个merge A B 形象地说就是就是将栈B堆到栈A上. 题解:直接用list 的pop_back,push_back,splice 模拟, 坑:用splice,第一次超时,正要大改 发现是cin超时... #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> #include<cstring> #include<set> #includ…
题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <stdio.h> #include <iostream> #include <vector> #include <deque> #include <list> #define IO ios::sync_with_stdio(0);\ cin.tie();cout…
传送门 题意: 给出了三个新定义: E-prime : ∀ num ∈ E,不存在两个偶数a,b,使得 num=a*b;(简言之,num的一对因子不能全为偶数) E-prime factorization : 定义集合P由 E-prime 元素组成,定义 e = p1*p2*.....*pn:(p1,p2,....,pn ∈ P , |P| = n) E-factorial : 定义 e!! = 2*4*6*8*.........*e:(简言之,偶数e及其之前的偶数连乘积) 输出一个数 e ,求…
Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given initially empty stacks, there are three types of operations: 1 s v: Push the value onto the top of the -th stack. 2 s: Pop the topmost value out of the -th stack, and print that…
[传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 [题目大意]初始有n个空栈,现在有如下三种操作: (1) 1 s v  即 s.push(v) (2) 2 s 即 s.pop() 输出弹出的元素,如果栈s为空则输出 "EMPTY" (3) 3 s t 把t栈元素全部移到s栈中,使s的尾部与t的首部相连. 现在有若干上述三种类型的操作,遇到操作2则输出相应内容. [题解]由于站的数量n和操作次数…
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ int t; cin >> t; while(t--){ int n; cin >> n; string s; cin >> s; ; bool l = true; int i; ;i >= ;i -= ){ sum += *i+; if(l){ '){ a[i]…
Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given  initially empty stacks, there are three types of operations: 1 s v: Push the value  onto the top of the -th stack. 2 s: Pop the topmost value out of the -th stack, and print tha…
Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given  initially empty stacks, there are three types of operations: 1 s v: Push the value  onto the top of the -th stack. 2 s: Pop the topmost value out of the -th stack, and print tha…
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 题意 模拟栈的三种操作 第一种 push 将指定元素压入指定栈 第二种 pop pop出指定栈的栈顶元素 如果栈空 输出 EMPTY 第三种 Move a b 将 b 中的所有元素 移动到 栈a中 思路 本来想到用 双端队列 因为 在移动的时候 比较方便 但是MLE了 后来想到用链表 但是在 比赛的时候 没有想到 有 STL 中 有LIST 这个容器 手写…
Seven Segment Display Time Limit: 1 Second      Memory Limit: 65536 KB A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix d…
ZOJ  4016 list用法https://www.cnblogs.com/LLLAIH/p/10673068.html 一开始用普通的栈做,超内存,链表模拟栈也没写出来orz.补题发现list超好用,真的-6- 有三个操作:1/向栈里添加数 2/输出栈顶元素然后pop掉 3/将栈b合并到栈a里并将栈b清空(注意合并后的顺序) 注意注意注意!!一定要将需要使用的list元素进行清空否则会WA!! 注意合并两个list序列时,用merge的话,会将合并后的序列进行默认的升序排列,所以这题要用s…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 直接用栈爆内存,看网上大神用数组实现的,构思巧妙,学习了! AC代码: /* * 用数组实现栈的一些操作 */ #include <cstdio> #include <cstring> using namespace std; const int maxn = 300005; int arr[maxn]; //存放所有的数据 //top代表栈…
个人心得:算法书中的第一个例题就来了一个下马威,虽然题意很好理解但是做起来确实这么不顺手,所以自己对于搜索和堆栈理解的并不是很好, 以前也是很多这样的题目无法实施,这题要做的很明确就是输出正确的能依靠栈完成字符串的变化,很明显答案很多所以必须搜索确定出栈的位置, 但是自己无法控制好搜索,题解很清晰, 个人收获:vector 可以用于搜索更方便,然后搜索的时候注意细节和base基准情况 题目: How can anagrams result from sequences of stack oper…
传送门 题意: 给出一个序列,你可以将任意一个数移到最前面: 求最少需要移动多少次,可以是此序列变成非递减序列: 思路: 定义 (ai,aj) 为逆序对 ( i < j , ai > aj ), 求出 aj 的最大值,用变量 curMax 存储: 遍历一遍数组,求解 ans: 对于∀ i ∈[1,n] ①如果 ai < curMax , ans++; ②如果 ai == curMax , 那么需要特殊判断: (2.1)如果 ai 之前不曾出现比 curMax 大的数,不需要移动: (2.…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2654    Accepted Submission(s): 1143 Problem Description The Czech Technical Universi…
ZOJ - 4016 vector又T又M list是以链表的方式存储的 是一个双向链表 元素转移操作中,不能一个个遍历加入到s中,list独有的splic函数可以在常数时间内实现合并(并删除源list) splice()有三种调用形式:第一种: list1.splice(it1, list2).将list2中的所有元素拷贝到list1中.在list1中的起始位置是it1.复制结束后,list2将为空. 第二种调用形式:list1.splice(it1, list2, it2)这个功能是将lis…
C - Mergeable Stack ZOJ - 4016 一开始用stl中内置的栈来写,其中第三个操作,我先复制到一个数组,再将其倒给另一个栈 这个方法有两个错误的地方: 1.栈在内存很大需要扩容时,内存会成倍增长,解决办法是提前规定每个栈的大小,但这样还是不适用于这题 2.如果每次都用一个数组来过度,时间复杂度是O(N*N) #include<iostream> #include<cstdio> using namespace std; const int maxn=3*1e…
转载:http://blog.csdn.net/morewindows/article/details/6950881 栈(statck)这种数据结构在计算机中是相当出名的.栈中的数据是先进后出的(First In Last Out, FILO).栈只有一个出口,允许新增元素(只能在栈顶上增加).移出元素(只能移出栈顶元素).取得栈顶元素等操作.在STL中,栈是以别的容器作为底部结构,再将接口改变,使之符合栈的特性就可以了.因此实现非常的方便.下面就给出栈的函数列表和VS2008中栈的源代码,在…
heap是堆,stack是栈 stack的空间由操作系统自动分配/释放,heap上的空间手动分配/释放. stack空间有限,heap是很大的自由存储区 C中的malloc函数分配的内存空间即在heap上,C++中对应的是new操作符. 程序在编译期对变量和函数分配内存都是在stack(栈)上进行,且程序运行过程中的函数调用时参数的传递也在栈上进行.…
ZOJ 2562 More Divisors(高合成数) ACM 题目地址:ZOJ 2562 More Divisors 题意:  求小于n的最大的高合成数,高合成数指一类整数,不论什么比它小的自然数的因子数目均比这个数的因子数目少. 分析:  网上都叫它反素数,事实上我查了一下,翻素数应该是正着写倒着写都是素数的素数.这个应该叫高合成数,见Wikipedia: Highly composite number 高合成数有下面特征:  where p1<p2<⋯<pk are prime,…
Stack(栈)是一种后进先出的数据结构,下面介绍一下栈的具体运用: 一.Stack 中的 empty 函数 stack<int> s( 5 , 10) ; s.empty()  ;       // 返回的是栈中是否为空,如果是返回true ,否则返回 false : 二.stack 中的 size 函数 stack<int> s( 5 , 10 ) ; s.size() ;  // 返回的是栈中元素的个数: 三.stack 中的 top 函数 stack<int>…
ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds      Memory Limit: 65536 KB This is a very popular game for children. In this game, there's a cube, which consists of 3 * 3 * 3 small cubes. We can unwrap the cube, it will become like this: 这是个有名的儿童游戏.游戏…
stack():沿着新的轴加入一系列数组. vstack():堆栈数组垂直顺序(行) hstack():堆栈数组水平顺序(列). dstack():堆栈数组按顺序深入(沿第三维). concatenate():连接沿现有轴的数组序列. vsplit():将数组分解成垂直的多个子数组的列表. 1.numpy.stack()函数 函数原型:numpy.stack(arrays,axis=0) 示例:   2.numpy.hstack()函数 函数原型:numpy.hstack(tup),其中tup是…
POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径) Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shar…
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations onl…