HDU 1022(火车过站 栈)】的更多相关文章

题意是给定火车进站的序列和出站的序列,问能否完成转换,若能输出过程. 和另一道以火车进站为背景的栈应用题类似,但增加了对于过程的输出,只需要多记录一下进出站顺序即可. #include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); ]; stack<char> q; ],go[]; while(cin >> n) { cin >> com…
 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 题目大概意思:有N辆火车,以序列1方式进站,判断是否能以序列2方式出栈.进站不一定是一次性进入,也就是说中途可以出站. #include <cstdio> #include <stack> #include <iostream> #include <algorithm> using namespace std; int main() { ],…
Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 51413    Accepted Submission(s): 19341 Problem Description As the new term comes, the Ignatius Train Station is very busy nowaday…
题目大意:有n辆火车,按一定的顺序进站(第一个字符串顺序),问是否能按规定的顺序出站(按第二个字符串的顺序出去),如果能输出每辆火车进出站的过程. 题目思路:栈的特点是先进后出,和题意类似,还有有一种情况是:开进来立马有开出去.并用vis[]数组的0,1标记进出站情况. 具体看代码 #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm&…
#include<iostream> #include<vector> #include<cstring> #include<string> #include<stack> #include<map> using namespace std; ]; /* 栈的应用 若in[i]==out[j]则先进栈后立即出栈,此时只需i++,j++: 若in[i]!=out[j]检查栈首是否为out[j],若是,则出栈,并j++,否则将in[i]入…
A - Train Problem I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1022 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to…
http://career-oj.huawei.com/exam/ShowSolution?method=SolutionApp&id=2282 给定一个正整数N代表火车数量,0<N<10,接下来输入火车入站的序列,一共N辆火车,每辆火车以数字1-9编号.要求以字典序排序输出火车出站的序列号.其实也就是输出所有可能的出栈序列. 样例输入: 3 1 2 3 样例输出: 1 2 31 3 22 1 32 3 13 2 1 解答: 其实核心就是一个栈,对于第K个数,在第K个数进栈之前,前面的…
hdu 5033 buiding(单调栈) 某年某月某天,马特去了一个小镇.这个小镇如此狭窄,以至于他可以把小镇当作一个枢纽.在镇上有一些摩天大楼,其中一栋位于xi,高度为hi.所有的摩天大楼位于不同的地方.为了简化题目,假设摩天大楼没有宽度.由于摩天大楼如此之高,马特几乎看不到天空.对于马特所在的位置,他想知道他能看到天空的角度范围有多大.假设马特的身高是0.可以保证,对于每个查询,马特的左右两边至少有一座建筑物,而且他的位置上没有建筑物.建筑物的数量n<1e5,查询次数Q<1e5. 我用常…
1757: 火车入站 Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 512     Solved: 135 Description 火车站人们总是在站台等待列车进站,一个站台有火车停留的时候就不能有其他火车进入,今天有n辆火车经过,已知它们进站时间Si以及出站时间Ti,进站时间到出站时间之间火车必须有一个站台给它停靠,问让所有火车都能按时停靠,至少要安排多少个站台给这些火车 In…
http://acm.split.hdu.edu.cn/showproblem.php?pid=1022 题意:给出火车的进站与出站顺序,判断是否可以按照给出的出站顺序出站. #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <vector> #include <algorithm> #include <ma…
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes…
Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 41471    Accepted Submission(s): 15510 Problem Description As the new term comes, the Ignatius Train Station is very busy nowaday…
Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30245    Accepted Submission(s): 11434 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 45375    Accepted Submission(s): 16966 Problem Description As the new term come…
传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a pr…
火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const int MAX_N = 10; char inOrder[MAX_N], outOrder[MAX_N], stk[MAX_N]; bool rs[MAX_N<<2]; int n; int main() { while (scanf("%d", &n) != EOF)…
Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 53352    Accepted Submission(s): 20006 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays…
#include<stdio.h> #include<stack> #include<string.h> #define N 20 using namespace std; int main() { stack<char>S; int n, i, j, k, a[N]; char s1[N], s2[N]; while(scanf("%d", &n) != EOF) { while(!S.empty())//清空栈 S.pop()…
Train Problem I Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^).…
Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20521    Accepted Submission(s): 7712 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays…
Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 18095    Accepted Submission(s): 6764 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays.…
Train Problem I 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all o…
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes…
题目链接 按序列a进栈,问能不能按序列b出栈. 遍历b,如果当前元素进过栈了,那么必须和栈顶元素相同.如果没进过栈则按a序列压栈,直到遇到当前元素. #include <iostream> #include <stack> #include <string.h> using namespace std; ],outo[]; ]; ]; int n; int main(){ int i,j; stack<char > s; while(scanf("…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 又是一道栈的练习,这次也是没有用到STL中的栈来实现.用来保存操作过程的数组(process[])一定要开得足够大(一开始开小了导致wa) #include <iostream> #include <string.h> #include <stdio.h> using namespace std; ; int main() { char o1[maxn], o2[ma…
题目链接 题意:n个建筑物,Q条询问,问所在的位置,看到天空的角度是多少,每条询问的位置左右必定是有建筑物的. 思路 : 维护一个单调栈,将所有的建筑物和所有的人都放到一起开始算就行,每加入一个人,就维护栈里的建筑物的高度,也就是说这个人所能够看到的建筑物时在栈里的,但是这个人看不到的就删掉,例如下图,中间三个点可以删掉了,因为角度问题中间三个是看不到的,所以不会影响最终求得角度 还有一种情况,就是下述的情况,不停的维护单调栈,人站在不同的地方角度也是不一样的. 维护的是相邻两建筑顶(xi,hi…
题意:N 幢楼排成一列(1<=N<=10^5),各楼有横坐标 xi(1<=xi<=10^7) 以及高度 hi(1<=hi<=10^7),在各楼之间的Q个位置(1<=Q<=10^5),问这些位置能够仰望天空的夹角是多少度. 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5033 -->>将楼和人的位置一起按 x 排序.. 从左往右扫,单调栈维护斜率小的. . 从右往左扫.单调栈维护斜率大的.. #i…
Description There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds were extremely limited that time. It was possible to establish only a surface track. Moreove…
http://acm.hdu.edu.cn/showproblem.php? pid=2870 Largest Submatrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1569    Accepted Submission(s): 748 Problem Description Now here is a matrix wi…
题意:给一些建筑物,x表示横坐标,h表示高度,然后查询某些坐标x,问从该点看向天空的最大张角是多大. 解法:离线操作,读入所有数据,然后按x升序排序,对每一个查询的x,先从左到右,依次添加x坐标小于x的建筑物,加入一个建筑物的条件: 1.此建筑物高度大于栈中的前一个,这个必然是最优的. 2.加入这个建筑物后不能使相对斜率: stk[top-2]~stk[top-1] 比a[j]~stk[top-1]大(负数),即出现凹形,否则会出现这种: 如图,即中间那个根本没用了,加入第三根的时候就要判一下.…