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. storm并发机制,通信机制,任务提交

    一.storm的并发 (1)Workers(JVMs):在一个物理节点上可以运行一个或多个独立的JVM进程.一个Topology可以包含一个或多个worker(并行的跑在不同的物理机上),所以work ...

  2. python 多线程小练习

    需求:有100个数据,启动5个线程,每个线程分20个数据,怎么把这20个数据分别传给每个线程. 1. 利用多线程实现 import threading nums = list(range(100)) ...

  3. HTML鼠标悬停改变样式

    a.tt:hover {color: #FF0000;} <a class="tt" href="test.html">test</a> ...

  4. python直接赋值、浅拷贝和深拷贝

    # 解: # import copy # names1=['Amir','Barry','Cgakes','Dao',[11,22,33]] # names2=names1#直接赋值,指向同一个对象 ...

  5. chrome浏览器使用

    1.如何打开多个历史网页.这个需求是这样的,有时候开了多个网页查找资料,但是又还没有做完,然后又需要重启电脑.显然重启电脑后再开启浏览器,一般都是显示浏览器的主页了,上次开的那些网页全部在历史记录里面 ...

  6. fafu 1413

    叉积的运用 ,不断的用叉积去判断 最小的拼图, 刚开始对点进行排序,每个人的排序规则不同做法可能不同,我是按照点的x轴进行x轴相同用y小的在前面,然后每个点按照最下的点开始进行查找 每次从一个点出发然 ...

  7. Linux中顿号

    ``的作用是运行``之间的命令,并且将命令运行的结果返回.一般shell脚本应该是这样:result=`ls -l` (用你的命令替换ls -l,这里只是举例)这样,result就有``里面的运行结果 ...

  8. Linux基础命令---gunzip

    gunzip 解压缩被gzip压缩过的文件.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法      gunzip [-ac ...

  9. Python安装selenium,配置火狐浏览器环境

    想用Python去编写自动化脚本进行网页访问时,遇到了一些问题, File "C:\Python34\lib\site-packages\selenium-3.0.0b2-py3.4.egg ...

  10. shell中参数及带色彩打印

    shell脚本中的一些函数参数说明如下: #!/bin/bash echo 显示参数的个数: $# echo 以单个字符串把每个参数连接起来: $* echo 显示脚本当前运行的进程id: $$ ec ...