HDU 3183 A Magic Lamp(二维RMQ)】的更多相关文章

题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且取的数最小,查询最小的操作用RMQ优化. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 10005; int N, M, d[m…
hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑出来m个数使得剩余的数字最小,串的序列不能改变 思路: 将问题转化为求在n个数中挑选n-m个数,使之最小.假设最极端的情况,所有最大的数字都在左侧,占据了m个位置,那么我们需要挑选的最小的数字的第一位就是在m+1位上.依次类推,第二位在m+2位上,最后一位也就在原串的最后一位上.反过来,假设最大的数…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question, and then the genie will realize one of her d…
A Magic Lamp                                                                               Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Kiki likes traveling. One day she finds a magic lamp, u…
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the genie in the lamp is not so kind. Kiki must answer a question…
原题目 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3964    Accepted Submission(s): 1605 Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the…
第一种做法是贪心做法,只要前面的数比后面的大就把他删掉,这种做法是正确的,也比较好理解,这里就不说了,我比较想说一下ST算法,RMQ的应用 主要是返回数组的下标,RMQ要改成<=(这里是个坑点,取连续数是可以的),他的转移方程为x = dp[i-1][j],y = dp[i-1][j+1<<(i-1)]; dp[i][j] = a[x] <= a[y] ? x : y; 这里既是转化为取n-m个数,首先在1 ~ m+1中必然选一个数,所以这个数就是n-m数中第一个数,记录所选的位置…
<题目链接> <转载于 >>>  > 题目大意: 给出一个长度不超过1000位的数,求删去m位数字以后形成的最小的数字是多少. 解题分析: 分析:我们可以把题目转化为这样一个模型:从A[1].A[2].…….A[n] n个数中选出n-m个数,使得组成的数最小.一.使用RMQ,设原数字长为n,那么除去m个数字后还剩n-m个数字.    下面的(一).(二)用到了抽屉原理(1)因为有n-m个数字,那么在0到m-1位置中最小的那个数字必是结果中的第一个数字,记录其位置为…
直接模拟   如果后一位比前一位小,那就一直 向前 pop()掉 维护他单调递增: #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<stdio.h> #include<vector> using namespace std; ]; ],num; int main( ) { while( scanf("%s%d&…
1.题目大意是,给你一个1000位的数,要你删掉m个为,求结果最小数. 思路:在n个位里面删除m个位.也就是找出n-m个位组成最小数 所以在区间 [0, m]里面找最小的数.相应的下标标号i 接着找区间 [i+1,m++]里面的最小数.对于下标为ii 接着找区间 [ii+1,m++]里面的最小数-- 这样就会找n-m个数了.区间这样安排的目的是为了保证取出来的数的顺序. 2代码: #include<cstdio> #include<cstring> #include<cmat…
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <ma…
A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7170    Accepted Submission(s): 2866 Problem Description Kiki likes traveling. One day she finds a magic lamp, unfortunately the geni…
http://acm.hdu.edu.cn/showproblem.php?pid=2888 题意:给出一个n*m的矩阵,还有q个询问,对于每个询问有一对(x1,y1)和(x2,y2),求这个子矩阵中的最大值,和判断四个角有没有等于这个最大值的. 思路:二维RMQ模板题.注意内存卡的挺紧的. #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using nam…
Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2377    Accepted Submission(s): 859 Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all intege…
<题目链接> <转载于 >>> > 题目大意: 给出一个N*M的矩阵,并且给出该矩阵上每个点对应的值,再进行Q次询问,每次询问给出代询问子矩阵的左上顶点和右下顶点,问该子矩阵的最大值是多少,并且判断该最值是否在该子矩阵的四个顶角上. 解题分析: 很明显求二维区间内的最值,需要用到二维RMQ,其中dp[i][j][k][l]表示左上角为(i,j),右下角为(i + 2 ^ k - 1, j + 2 ^ l - 1)这个矩形内的最值.注意这个四维数组不要开得太大,否则…
Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1646    Accepted Submission(s): 597 Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer…
题目:点这里 题意:给出一个n*m的矩阵,然后又Q个询问:每个询问有x1,y1,x2,y2,x1,y1为子矩阵的左上角坐标,x2,y2为右上角的坐标.求此子矩阵中元素最大值,判断最大值是否在子矩阵四个角上,在就输出yes,否则输出no. 分析:二维RMQ直接上代码. #include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> using namespace std;…
http://acm.hdu.edu.cn/showproblem.php?pid=2888 模板题  直接用二维rmq 读入数据时比较坑爹  cin 会超时 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; ][]; void rmq_init(int n, int m) { ; i <= n; i++) { ; j <= m; j++) dp[…
Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2513    Accepted Submission(s): 904 Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all intege…
有一个矩阵,每次查询一个子矩阵,判断这个子矩阵的最大值是不是在这个子矩阵的四个角上 裸的二维RMQ #pragma comment(linker, "/STACK:1677721600") #include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include <ctime> #include <vec…
题目传送门 Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7963   Accepted: 3822 Description FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the c…
Little Tommy is playing a game. The game is played on a 2D N x N grid. There is an integer in each cell of the grid. The rows and columns are numbered from 1 to N. At first the board is shown. When the user presses a key, the screen shows three integ…
Problem Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 <= i <= m, 1 <= j <= n ). Now he selects some sub-matrices, hoping to find the maximum number. Then he finds that there may be more tha…
Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4911   Accepted: 2392 Description FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfie…
题目描述 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入 第一行为3个整数,分别表示a,b,n的值第二行至第a+1行每行为b个非负整数,表示矩阵中相应位置上的数.每行相邻两数之间用一空格分隔.100%的数据2<=a,b<=1000,n<=a,n<=b,n<=1000 输出 仅一个整数,为a*b矩阵中所有“n*n正方形区域中的最大整数和最小整数的差值”的最小值. 样例输入 5 4 2 1 2 5 6 0 1…
点此看题面 大致题意: 求出一个矩阵中所有\(n*n\)正方形中极差的最小值. 另一种做法 听说这题可以用单调队列去做,但是我写了一个二维\(RMQ\). 二维\(RMQ\) \(RMQ\)相信大家都会的,而 二维\(RMQ\) 其实与普通\(RMQ\)是没什么区别的. 我们可以用\(Max_{i,j,k}\)来表示\((i,j)\sim(i+2^k,j+2^k)\)这个矩阵内的最大值,\(Min_{i,j,k}\)同理. 由于求的是一个正方形内的最大值与最小值,所以\((i,j)\sim(x,…
https://ac.nowcoder.com/acm/contest/700/I 二维RMQ,贴个板子,注意爆内存,用char就可以了,char也可以存负数. 然后二分枚举对角线长度,理由很简单. 矩阵变大,极值只会变大不会变小.满足单调性. #include<bits/stdc++.h> using namespace std; #define MAXN 501 int n,m,g; int rec[MAXN][MAXN]; char dp[MAXN][MAXN][11][11]; cha…
理想的正方形 省队选拔赛河南  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master       题目描述 Description 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入描述 Input Description 第一行为3个整数,分别表示a,b,n的值 第二行至第a+1行每行为b个非负整数,表示矩阵中相应位置上的数.每行相邻两数之间用一空格分隔. 输出描述 Output Descr…
题目描述 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入输出格式 输入格式: 第一行为3个整数,分别表示a,b,n的值 第二行至第a+1行每行为b个非负整数,表示矩阵中相应位置上的数.每行相邻两数之间用一空格分隔. 输出格式: 仅一个整数,为a*b矩阵中所有“n*n正方形区域中的最大整数和最小整数的差值”的最小值. 输入输出样例 输入样例#1: 5 4 2 1 2 5 6 0 17 16 0 16 17 2 1 2 10 2…
Cornfields Time Limit: 1000MS   Memory Limit: 30000K Total Submissions:8623   Accepted: 4100 Description FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he's looking to build the cornfiel…