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 接着找区 ...
随机推荐
- SVN出现xcrun: error: invalid active developer path(Mac)
Mac升级了系统,配置PHPStorm的SVN,出现如下错误: 具体提示的内容是:xcrun: error: invalid active developer path (/Library/Devel ...
- PAT 1101 Quick Sort[一般上]
1101 Quick Sort(25 分) There is a classical process named partition in the famous quick sort algorith ...
- weka数据挖掘拾遗(二)---- 特征选择(IG、chi-square)
一.说明 IG是information gain 的缩写,中文名称是信息增益,是选择特征的一个很有效的方法(特别是在使用svm分类时).这里不做详细介绍,有兴趣的可以googling一下. chi-s ...
- [LeetCode] questions conclustion_Path in Tree
Path in Tree: [LeetCode] 112. Path Sum_Easy tag: DFS input: root, target, return True if exi ...
- testng入门教程11 TestNG运行JUnit测试
现在,您已经了解了TestNG和它的各种测试,如果现在担心如何重构现有的JUnit代码,那就没有必要,使用TestNG提供了一种方法,从JUnit和TestNG按照自己的节奏.也可以使用TestNG执 ...
- iOS开发需要学习哪些内容?
看图:
- 7.8 Models -- The Rest Adapter
一.概述 默认的,store将会使用 DS.RESTAdapter来加载和存储records.这个RESTAdapter假定URLS和JSON关联每一个model是约定好的:这意味着,如果你遵循这个规 ...
- 删除排序数组中的重复数字 II
题目连接 http://www.lintcode.com/zh-cn/problem/remove-duplicates-from-sorted-array-ii/ 题目大意 跟进“删除重复数字”: ...
- Rpgmakermv(5) MiniLabel插件介绍
============================================================================ Introduction ========== ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON max_connection
zw版[转发·台湾nvp系列Delphi例程]HALCON max_connection procedure TForm1.Button1Click(Sender: TObject);var ho_I ...