上题目:

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. jQuery - 获取爱好

    <!DOCTYPE html > <html> <head> <title> 获取爱好 </title> <meta http-equ ...

  2. 批量梯度下降(Batch gradient descent) C++

    At each step the weight vector is moved in the direction of the greatest rate of decrease of the err ...

  3. # 深入理解Redis(二)——内存管理的建议与技巧

    引语 随着使用Redis的深入,我们不可避免的需要深入了解优化Redis的内存,本章将重点讲解Redis的内存优化之道,同时推荐大家阅读memory-optimization一文. 想要高效的使用Re ...

  4. pdf 转成 一张图片

    1.maven依赖 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfb ...

  5. # secure_link_module模块

    作用 制定并允许检查请求的链接的真实性以及保护资源免遭未经授权的访问 限制链接生效周期 首先检查nginx是否已安装模块 #nginx -V 输出nginx所有已安装模块,检查是否有ngx_http_ ...

  6. Oracle 关于oracle自带的行转列函数

    前言: 环境是java+hibernate+oracle11g 目标是将某表中根据id分组后将name字段的值拼接到一列中,且用“,“进行分割 试过用 wm_concat() 结合 group by ...

  7. SQLServer2008 使用BCP导入导出表数据

    --先开启cmdshell EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO EXEC sp_configure 'xp_c ...

  8. 微软CRM4.0 页面表单和腾讯QQ在线整合

    现在通过QQ和客户联系.洽谈业务及沟通感情的场合越来越多,在微软CRM表单上整合QQ可以方便的显示客户QQ在线状态,点击图标即可和客户进行QQ聊天. 客户在线状态: 客户离线状态: 输入QQ号码后即时 ...

  9. react基础篇二

    组件 & Props & 生命周期 组件可以将UI切分成一些独立的.可复用的部件,这样你就只需专注于构建每一个单独的部件. 组件从概念上看就像是函数,它可以接收任意的输入值(称之为“p ...

  10. 【sqli-labs】 less40 GET -Blind based -String -Stacked(GET型基于盲注的堆叠查询字符型注入)

    提交,页面正常,说明是')闭合的 http://192.168.136.128/sqli-labs-master/Less-40/?id=1')%23 http://192.168.136.128/s ...