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, and then the genie will realize one of her dreams. 
The question is: give you an integer, you are allowed to delete exactly m digits. The left digits will form a new integer. You should make it minimum.
You are not allowed to change the order of the digits. Now can you help Kiki to realize her dream?
 
Input
There are several test cases.
Each test case will contain an integer you are given (which may at most contains 1000 digits.) and the integer m (if the integer contains n digits, m will not bigger then n). The given integer will not contain leading zero.
 
Output
For each case, output the minimum result you can get in one line.
If the result contains leading zero, ignore it. 
 
Sample Input
178543 4
1000001 1
100001 2
12345 2
54321 2
 
Sample Output
13
1
0
123
321
 
Source
题意:给你一个数,在1000位内(字符串),删掉m个数,得到最小的数输出;
rmq :思路:第一位在len-m内;找到第n位以后,最后留下没有找数的数目(len-m-n),在n之后的区间找n+1;(0ms)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
char a[];
int dp[][];//存位置
char ans[];
int minn(int x,int y)
{
return a[x]<=a[y]?x:y;
}
void rmq(int len)
{
for(int i=; i<len; i++)
dp[i][]=i;
for(int j=; (<<j)<len; j++)
for(int i=; i+(<<j)-<len; i++)
dp[i][j]=minn(dp[i][j-],dp[i+(<<(j-))][j-]);
}
int query(int l,int r)
{
int x=(int)(log((double)(r-l+))/log(2.0));
return minn(dp[l][x],dp[r-(<<x)+][x]);
}
int main()
{
int x,y,z,i,t;
while(~scanf("%s%d",a,&x))
{
int len=strlen(a);
rmq(len);
int st=,en=x;
int flag=;
for(i=; i<len-x; i++)
{
int number=query(st,en);
//cout<<st<<" "<<en<<" "<<number<<endl;
st=number+;
en=i+x+;
ans[flag++]=a[number];
}
for(i=; i<flag; i++)
if(ans[i]!='')
break;
for(t=i; t<flag; t++)
printf("%c",ans[t]);
if(i==flag)
printf("");
printf("\n");
}
}

暴力思路:在字符串中查找a[i]>a[i+1];找到第一个删掉;如果没有,说明是一直上升;最后的数最大,删掉最后一个;

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
vector<int>v;
char a[];
int main()
{
int x,y,z,i,t;
while(~scanf("%s%d",a,&x))
{
v.clear();
int len=strlen(a);
for(i=; i<len; i++)
v.push_back(a[i]-'');
while(x--)
{
int flag=;
int len=v.size();
for(i=; i<len-; i++)
{
if(v[i]>v[i+])
{
flag=;
v.erase(v.begin()+i);
break;
}
}
if(flag)
v.erase(v.begin()+len-);
}
for(i=; i<v.size(); i++)
if(v[i])
break;
for(t=i; t<v.size(); t++)
printf("%d",v[t]);
if(i==v.size())
printf("");
printf("\n");
}
return ;
}

hdu 3183 A Magic Lamp rmq或者暴力的更多相关文章

  1. hdu 3183 A Magic Lamp RMQ ST 坐标最小值

    hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...

  2. hdu 3183 A Magic Lamp(RMQ)

    题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...

  3. HDU 3183 - A Magic Lamp - [RMQ][ST算法]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...

  4. HDU 3183 A Magic Lamp(RMQ问题, ST算法)

    原题目 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. hdu 3183 A Magic Lamp(RMQ)

    A Magic Lamp                                                                               Time Limi ...

  6. HDU 3183 A Magic Lamp(二维RMQ)

    第一种做法是贪心做法,只要前面的数比后面的大就把他删掉,这种做法是正确的,也比较好理解,这里就不说了,我比较想说一下ST算法,RMQ的应用 主要是返回数组的下标,RMQ要改成<=(这里是个坑点, ...

  7. hdu 3183 A Magic Lamp 【RMQ】

    <题目链接> <转载于 >>>  > 题目大意: 给出一个长度不超过1000位的数,求删去m位数字以后形成的最小的数字是多少. 解题分析: 分析:我们可以把题 ...

  8. HDU 3183 A Magic Lamp

    直接模拟   如果后一位比前一位小,那就一直 向前 pop()掉 维护他单调递增: #include<iostream> #include<cstring> #include& ...

  9. hdu 3183 A Magic Lamp(给一个n位的数,从中删去m个数字,使得剩下的数字组成的数最小(顺序不能变),然后输出)

    1.题目大意是,给你一个1000位的数,要你删掉m个为,求结果最小数. 思路:在n个位里面删除m个位.也就是找出n-m个位组成最小数 所以在区间 [0, m]里面找最小的数.相应的下标标号i 接着找区 ...

随机推荐

  1. 去掉python的警告

    1.常规警告 import warnings warnings.filterwarnings("ignore") 2.安装gensim,在python中导入的时候出现一个警告: w ...

  2. Linear Regression Using Gradient Descent 代码实现

    参考吴恩达<机器学习>, 进行 Octave, Python(Numpy), C++(Eigen) 的原理实现, 同时用 scikit-learn, TensorFlow, dlib 进行 ...

  3. thinkphp input

    变量修饰符 input函数支持对变量使用修饰符功能,可以更好的过滤变量. 用法如下: input('变量类型.变量名/修饰符'); 或者 Request::instance()->变量类型('变 ...

  4. c# 获取某个进程的CPU使用百分百(类似任务管理器中显示CPU)

    using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using S ...

  5. CAMediaTiming`协议(9.1 图层时间)

    #CAMediaTiming`协议 CAMediaTiming协议定义了在一段动画内用来控制逝去时间的属性的集合,CALayer和CAAnimation都实现了这个协议,所以时间可以被任意基于一个图层 ...

  6. Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(二)——Struts2集成

    1. pom.xml文件添struts2依赖jar包: <!-- 与Struts2集成必须使用 --> <dependency> <groupId>org.spri ...

  7. 网站app原型设计工具:axure,Mockups,墨刀

    网站app原型设计工具:axure,Mockups,墨刀 Balsamiq Mockups 3 网站原型设计工具非常高效,非常简单,几分钟就能搞定比axure好用很多 墨刀 - 免费的移动应用原型与线 ...

  8. DNS视图及压力测试(四)

    Bind安全控制选项 Allow-transfer {}; #用于控制区域传送文件 Allow-query {}; #通常用于服务器是缓存名称服务器时,控制查询客户端 Allow-recursion ...

  9. STM32硬件IIC

    /** * @brief 写一个字节到I2C设备中 * @param * @arg pBuffer:缓冲区指针 * @arg WriteAddr:写地址 * @retval 正常返回1,异常返回0 * ...

  10. Python Web学习笔记之递归和迭代的区别

    电影故事例证:迭代——<明日边缘>递归——<盗梦空间> 迭代是更新变量的旧值.递归是在函数内部调用自身. 迭代是将输出做为输入,再次进行处理.比如将摄像头对着显示器:比如镜子对 ...