Passing the Message What a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flower” kindergarten are prepared to have an excursion. Before kicking off, teacher Liu tells them to stand in a row. Teacher Liu has an important messag…
题目链接:hdu 3410 Passing the Message 题意: 说那么多,其实就是对于每个a[i],让你找他的从左边(右边)开始找a[j]<a[i]并且a[j]=max(a[j])(k+1<j<i),a[k]>a[i]. 题解: 从左往右维护一个递减的单调队列,每次都从尾巴开始把比a[i]的踢掉,最后踢的那个就是答案. 右边同理. #include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=b;i++…
可以先处理出每个a[i]最左和最右能到达的位置,L[i],和R[i].然后就只要询问区间[ L[i],i-1 ]和区间[ i+1,R[i] ]最大值位置即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue…
What a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flower” kindergarten are prepared to have an excursion. Before kicking off, teacher Liu tells them to stand in a row. Teacher Liu has an important message to announce, but s…
http://acm.hdu.edu.cn/showproblem.php?pid=3410 Passing the Message Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 827    Accepted Submission(s): 546 Problem Description What a sunny day! Let’s…
思路: 单调栈. 鄙人的记忆:按当前为最大值的两边延伸就是维护单调递减栈. //#include <bits/stdc++.h> #include <iostream> #include <stack> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <queue> #include <…
Passing the Message http://acm.hdu.edu.cn/showproblem.php?pid=3410 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1051    Accepted Submission(s): 683 Problem Description What a sunny day! Let’s…
HDU 5818 Joint Stacks(联合栈) Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 A stack is a data structure in which all insertions and deletions of entries are made at one end, called the "top" of…
题意: 给定n长的数组(下标从1-n)(n个人的身高,身高各不同样 问:对于第i个人,他能看到的左边最矮的人下标.(假设这个最矮的人被挡住了,则这个值为0) 还有右边最高的人下标,同理若被挡住了则这个值为0 输出n行,每一个人左右2边的下标. 单调队列,对于 front - rear 的队列(注意出队都是在rear,入队也是在rear) 当增加元素x,若这队列是单调递增的,显然q.front() <= x , 反之若>x ,则把队首元素弹掉,这样就能保持单调性. 若弹掉了队首元素,在此题中就相…
Clairewd’s message 题意:先一个转换表S,表示第i个拉丁字母转换为s[i],即a -> s[1];(a为明文,s[i]为密文).之后给你一串长度为n<= 100000的前面为密文后面为明文的串:让你通过密码转换表S在这个串的后面添加字符,使得前面的密文翻译成明文之后与后面相对应,最后输出添加字符后的串(前面密文照常输出): Sample Input 2 abcdefghijklmnopqrstuvwxyz abcdab qwertyuiopasdfghjklzxcvbnm q…
题意: 给出一个数组,问你对于第i个数,从最后一个比它大的数到它之间比它小的数中最大的那个数的下标,以及它右边到第一个比它大的数中比它小的数中最大的那一个数的下标<下标从1开始>. eg:5 2 4 3 1  l    0 0 2 0 0        对5来说左边比它小的数没有,所以是0.对2来说左边比它小的数没有,所以是0.对4来说左边比它小的数是2,所以下标是2.  r   3 0 4 5 0         对5来说右边比它小的数中最大的是4,是第3个,所以答案是3.对2来说右边比它小…
Isabella's Message Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4119 Description Isabella and Steve are very good friends, and they often write letters to each other. They exchange funny experiences, talk ab…
传送门: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…
http://acm.hdu.edu.cn/showproblem.php?pid=5875 单调栈,预处理to[i]表示第一个比a[i]小的数字,一直跳就可以. 这题是数据水而已. 这里学习下单调栈. 构造一个单调递增的栈,并且记录元素大小的同时记录它的id. 每次进来一个小的元素的话,就出栈,同时出栈的这个元素的to[id] = i了,因为这个元素是当时最大的.然后这个a[i]是第一个能让它出栈的,所以就是它了.后面的同理. #include <cstdio> #include <c…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important messages and she was preparing for sending it to ykwd. They had agreed that ea…
HDU 4924 Room and Moor 题目链接 题意:给定一个01组成的a序列.要求一个b序列,b序列每一个数值为[0, 1]之间的数,而且b序列为非递减序列,要求∑(ai−bi)2最小,求这个最小值 思路:推理,非常easy看出,开头一段的0和末尾一段的1等于没有.然后中间每段相似111000这样1在前,0在后的序列.都能够列出一个公式,非常easy推出选择的x为共同的一个值,为1的个数/(1的个数+0的个数)a,那么问题就变成要维护一个递增的x.利用一个栈去做维护,假设遇到一个位置递…
题意: 给你一个A数列,让你求一个单调递增的B数列(0<=bi<=1),使得sum{(ai-bi)^2}最小. 思路: 很明显,如果A = 0...01...1,那么bi=ai即可. 可以证明,如果 A = 1...10...0,那么所有bi达到同一个值的时候取得最优值. 假设 ai = 1, aj = 0, 那么 i<j ,所以bi<=bj. 若bi != bj,那么增大bi的值,或者减小bj的值都可以得到更优的结果. 所以,bi=bj. 所以,如果A数列里面出现了形如 &quo…
传送门 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…
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…
题目大意: 给你一个无向图,问加一条边之后最少还剩下几座桥. (注意重边处理)   分析:其实当我们把边双连通分量给求出来之后我们就能将连通块求出来,这样我们就可以重新构图.重新构造出来的图肯定是一颗树了, 那么问题就转化为求树的哪两个节点的距离最长.我们可以随便找一个点S开始BFS, BFS到这个点最远的那个点P,然后再从这个最远点P开始BFS,BFS到P最远的点E,  PE之间的距离就是这个图上最大的距离.   注:此题需要手动扩栈 #pragma comment(linker, "/STA…
题意: 给一个0和1组成的序列a,要构造一个相同长度的序列b.b要满足非严格单调,且 值为0到1的实数.最后使得  sum((ai-bi)^2)最小. 算法: 首先a序列開始的连续0和末尾的连续1是能够不考虑的. 由于仅仅要b序列相应开头为0. 末尾为1,既不影响单调性又能使相应的(ai-bi)^2=0. 然后, 先找111100.11100.10这样以1開始以0结束的序列块.每一块相应的b值相等且均为 这一块的平均值,即1的个数/0和1的总个数. 可是要满足b的单调性,则我们用栈来维护,假设后…
Isabella's Message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1365 Accepted Submission(s): 400 Problem Description Isabella and Steve are very good friends, and they often write letters to ea…
#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]入…
题目大意:有n辆火车,按一定的顺序进站(第一个字符串顺序),问是否能按规定的顺序出站(按第二个字符串的顺序出去),如果能输出每辆火车进出站的过程. 题目思路:栈的特点是先进后出,和题意类似,还有有一种情况是:开进来立马有开出去.并用vis[]数组的0,1标记进出站情况. 具体看代码 #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm&…
Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important messages and she was preparing for sending it to ykwd. They had agreed that each letter of these messages would be transfered to a…
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^).…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目大意:题目大意就是给以一段字符xxxxzzz前面x部分是密文z部分是明文,但是我们不知道是从哪里将密文和明文分开的, 密文是完整的,明文可能是不完整的,需要你补全,使得明文长度尽可能短. 解题思路: 因为密文至少占一半长度,所以从mid~len先假设为明文,然后将明文转成密文求出nxt[len](nxt[len]<=len-nxt[eln],不断递归nxt[len]直到满足条件)即为明文长…
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…
区间的价值 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description   我们定义“区间的价值”为一段区间的最大值*最小值. 一个区间左端点在L,右端点在R,那么该区间的长度为(R−L+1). 现在聪明的杰西想要知道,对于长度为k的区间,最大价值的区间价值是多少. 当然,由于这个问题过于简单. 我们肯定得加强一下. 我们想要知道的是,对于长度为1…
进制转换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 63039    Accepted Submission(s): 34261 Problem Description 输入一个十进制数N,将它转换成R进制数输出.   Input 输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16, R<…