上题目:

296. Sasha vs. Kate

Time limit per test: 1 second(s)
Memory limit: 65536
kilobytes
input: standard
output: standard

During the regular Mars's World Finals Subregional Programming Contest a boy Sasha lost N
"Mars" bars of chocolate to a girl Kate. But for two years already
Sasha does not hurry to pay his debt. And now Sasha and Kate decided
that Sasha will give Kate P chocolate bars, where number P can be obtained from the number N by removing exactly K
decimal digits. Sasha generously let Kate to choose digits to be
removed. Your task is to find out how many bars Sasha will give Kate. Of
course Kate will choose K digits from the number N in such a way that the resulting number P would be maximal.

Input

The first line of the input file contains two integer numbers N and K (1≤ N≤ 101000; 0≤ K≤ 999). Number K is strictly less than the number of digits in N. N will not have any leading zeros.

Output

Output the unknown P.

Example(s)
sample input
sample output
1992 2
99
sample input
sample output
1000 2
10

  题意是给你一个最多有1001的数字,然后让你剔除其中的某K个数字,求可以得到的最大的数字。

  这一题用贪心思想。

这一题一开始读错题目,以为是挑K个数字,还以为是连续的,然后就WA了两次。后来终于看清题目了。然后就开始了各种yy,想过的思路有不少,最后列举了几个数字,找到了一点规律。

规律是这样的:当第i个数字比后一个数字小的话,把它删掉可以比删掉其他数字的结果得到更大的结果,然后如果后面的数字等于或者小于当前的数字的话,说明当前的数字暂时可以不用删掉,然后对i+1操作。

当然,这个规律还不完善,如果数字为32121,要求删掉2个数字的话,那当然是删掉两个1,可是刚才的思路只删除了一个1,同时如果在外面加一个循环也不能解决问题,如果序列式是32112的话就可以很好地得到正确答案,那应该怎么做呢,暂时的做法是在所有数字的结尾加一个INF,这是根据我的代码的结构(我是用栈来实现的)写出来的解决方案= =,好像有点XX(= =),AC的代码有bug= =现在改了一下。听其他同学的解法好像用了一个for和一个while就搞定了。= =

上代码:

 #include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <algorithm>
#define MAX 300000+10
using namespace std; int s[MAX];
stack<int> S; int main()
{
//freopen("data.txt","r",stdin);
int i,j,n,k,e,h;
char c;
k=;
memset(s,-,sizeof(s));
while((c=getchar())!=' ')
{
s[k]=c-'';
k++;
}
scanf("%d",&n);
h=n;
i=;
//S.push(s[i]);
//i++;
while(h)
{
while(!S.empty() && s[i]>S.top())
{
S.pop();
h--;
if(h==) break;
}
if(h==) break;
S.push(s[i]);
i++;
//if(s[i]==-1) break;
}
h=S.size();
j=;
for(i--;j<h;j++,i--)
{
s[i]=S.top();
S.pop();
}
//e=0;
//for(j=0;j<h;j--) e=e*10+p[j];
if(i<k)
for(i++;i<k;i++)
{
printf("%d",s[i]);
//e=e*10+s[i];
}
else printf("");
printf("\n");
return ;
}

296

SGU - 296 - Sasha vs. Kate的更多相关文章

  1. SGU 296.Sasha vs. Kate(贪心)

    题意: 给出长度为n(<=1000)的一个数.输出删掉k个数字后的最大值. Solution: 简单贪心. s[i]代表数字s的第i位. 从前往后第一个满足s[i]>s[i-1]的位置,最 ...

  2. 今日SGU 5.22

    SGU 296 题意:给你一个最多1000位的数,让你删除k位使得剩下的数最大 收获:贪心 #include<bits/stdc++.h> #define de(x) cout<&l ...

  3. 【Codeforces718C】Sasha and Array 线段树 + 矩阵乘法

    C. Sasha and Array time limit per test:5 seconds memory limit per test:256 megabytes input:standard ...

  4. SGU 495. Kids and Prizes

    水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...

  5. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  6. 【SGU】495. Kids and Prizes

    http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...

  7. SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...

  8. Ubuntu 汉化及kate汉化和使用自带终端的解决方式

    汉化方法:1,打开屏幕上方的“system”(系统),里面有个“Administration”(系统管理),选择“Snaptic Package Manager”(软件包管理器),打开,输入密码后进入 ...

  9. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

随机推荐

  1. luogu2085 最小函数值

    题目大意 有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Ai*x^2+Bi*x+Ci (x,Ai,Bi,Ci∈N*).给定这些Ai.Bi和Ci,请求出所有函数的所有函数值中最小的m个. ...

  2. 在Twitter信息流中大规模应用深度学习——推文的相关度计算使用了深度学习

    我们如何对信息流进行排序? 在引入排序算法之前,信息流的组成非常简单:收集所有由你的关注对象在你最后一次登录Twitter之后发送的推文,再将它们按照时间倒序显示出来.这个看起来很简单,但要为数以亿计 ...

  3. hdu 1213(并查集模版题)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. codeforces round #420 div2

    A:暴力枚举 模拟 #include<bits/stdc++.h> using namespace std; ; int n; int a[N][N]; int main() { scan ...

  5. Java 解析Json数据

    Json格式字符串{success:0,errorMsg:"错误消息",data:{total:"总记录数",rows:[{id:"任务ID" ...

  6. Anagram Groups(字符串)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2316 理解错一点题意就能WA到死...题中对于 ...

  7. 《疯狂Python讲义》重要笔记——Python简介

    简介 Python是一种面向对象.解释型.弱类型的脚本语言,同时也是一种功能强大的通过语言,它提供了高效的高级数据结构,还有简单有效的面向对象编程. 在大数据.人工智能(AI)领域应用广泛,因此变得流 ...

  8. go之结构体

    一.关于结构体 简述 1.go 语言的切片可以存储同一类型的数据,但是结构体可以为不同项定义不同的数据类型 2.结构体是有一系列具有相同类型或不同类型的数据构成的数据集合 3.因为go 没有类似于类的 ...

  9. DCOM 找不到 office word 的解决方法

    1. 在运行里面  输入     comexp.msc -32  2.在“DCOM配置”中,为IIS账号配置操作Word(其他Office对象也一样)的权限. 具体操作:“组件服务(Component ...

  10. (三)Appium-desktop 打包

    appium-desktop经过二次开发后,需要打包为应用提供给其它同学使用.我们知道appium-desktop是使用electron来构建跨平台桌面应用程序.electron有electron-p ...