hdu 3183 A Magic Lamp rmq或者暴力
A Magic Lamp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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?
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.
If the result contains leading zero, ignore it.
1000001 1
100001 2
12345 2
54321 2
1
0
123
321
#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或者暴力的更多相关文章
- hdu 3183 A Magic Lamp RMQ ST 坐标最小值
hdu 3183 A Magic Lamp RMQ ST 坐标最小值 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题目大意: 从给定的串中挑 ...
- hdu 3183 A Magic Lamp(RMQ)
题目链接:hdu 3183 A Magic Lamp 题目大意:给定一个字符串,然后最多删除K个.使得剩下的组成的数值最小. 解题思路:问题等价与取N-M个数.每次取的时候保证后面能取的个数足够,而且 ...
- HDU 3183 - A Magic Lamp - [RMQ][ST算法]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 Problem DescriptionKiki likes traveling. One day ...
- HDU 3183 A Magic Lamp(RMQ问题, ST算法)
原题目 A Magic Lamp Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3183 A Magic Lamp(RMQ)
A Magic Lamp Time Limi ...
- HDU 3183 A Magic Lamp(二维RMQ)
第一种做法是贪心做法,只要前面的数比后面的大就把他删掉,这种做法是正确的,也比较好理解,这里就不说了,我比较想说一下ST算法,RMQ的应用 主要是返回数组的下标,RMQ要改成<=(这里是个坑点, ...
- hdu 3183 A Magic Lamp 【RMQ】
<题目链接> <转载于 >>> > 题目大意: 给出一个长度不超过1000位的数,求删去m位数字以后形成的最小的数字是多少. 解题分析: 分析:我们可以把题 ...
- HDU 3183 A Magic Lamp
直接模拟 如果后一位比前一位小,那就一直 向前 pop()掉 维护他单调递增: #include<iostream> #include<cstring> #include& ...
- hdu 3183 A Magic Lamp(给一个n位的数,从中删去m个数字,使得剩下的数字组成的数最小(顺序不能变),然后输出)
1.题目大意是,给你一个1000位的数,要你删掉m个为,求结果最小数. 思路:在n个位里面删除m个位.也就是找出n-m个位组成最小数 所以在区间 [0, m]里面找最小的数.相应的下标标号i 接着找区 ...
随机推荐
- mybatis中使用where in查询时的注意事项
我使用的时候collection值为mapper的参数名如:int deleteRoleByUserIds(@Param("userIds") String[] userIds); ...
- POJ2488:A Knight's Journey(dfs)
http://poj.org/problem?id=2488 Description Background The knight is getting bored of seeing the same ...
- oracle 之创建用户,表空间,授权,修改用户密码
1.创建表空间 create tablespace ilinkcargoagent logging datafile 'D:\app\Administrator\oradata\ilinkcargoa ...
- Android APP安装后不在桌面显示图标的应用场景举例和实现方法
最近在为公司做一款车联网的产品,由于公司本身擅长于汽车解码器的研发,所以该产品的诊断功能的实现除了使用目前市面上车联网产品中大量使用的OBD协议外,还会使用一些专车专用协议去实现一些特殊的诊断功能,如 ...
- [LeetCode] 261. Graph Valid Tree _ Medium tag: BFS
Given n nodes labeled from 0 to n-1 and a list of undirected edges (each edge is a pair of nodes), w ...
- 集成树模型使用自动搜索模块GridSearchCV,stacking
一. GridSearchCV参数介绍 导入模块: from sklearn.model_selection import GridSearchCV GridSearchCV 称为网格搜索交叉验证调参 ...
- python 多线程小练习
需求:有100个数据,启动5个线程,每个线程分20个数据,怎么把这20个数据分别传给每个线程. 1. 利用多线程实现 import threading nums = list(range(100)) ...
- java实现Comparable接口和Comparator接口,并重写compareTo方法和compare方法
原文地址https://segmentfault.com/a/1190000005738975 实体类:java.lang.Comparable(接口) + comareTo(重写方法),业务排序类 ...
- php 5.0 新字符串
简介:新字符串以“<<<”开始,后边紧跟子字符串标记,之后为字符串内容,最后用标记和分号结束. 说明:"<<<标记"后不要有空格符,否则可能出现 ...
- jq 自定义标注小组件 $.widget
html 部分 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...