当前位置:网站首页>1321: [example 6.3] deletion problem (noip1994)
1321: [example 6.3] deletion problem (noip1994)
2022-07-07 10:32:00 【A program ape who beats the keyboard violently】
1321:【 example 6.3】 Censoring problem (Noip1994)
The time limit : 1000 ms Memory limit : 65536 KB
Submission number : 25868 Passing number : 9164
【 Title Description 】
Enter a high precision positive integer n, Remove any of them s The rest of the numbers after the first number form a new positive integer according to the original left and right order . Programming for a given n and s, Find a scheme to make the new number of the remaining numbers minimum .
Output a new positive integer .(n No more than 240 position )
The input data do not need to be judged wrong .
【 Input 】
n
s
【 Output 】
The last remaining decimal .
【 sample input 】
175438
4
【 sample output 】
13
【 Algorithm analysis 】
greedy . loop s Time , Delete s A large number , The rest is the minimum .
【AC Code 】
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int N=340;
char n[N];
int s,len,m,x;
signed main()
{
scanf("%s%d",&n,&s);
x=len=strlen(n);
for(int i=1;i<=s;i++)
{
for(int j=0;j<len-1;j++)
if(n[j]>n[j+1])// If the current number is greater than the next number
{
for(int k=j;k<len-1;k++)n[k]=n[k+1];// Delete that number
break;// Out of the loop
}
len--;// length -1
}
while(n[m]=='0' and x>1)m++,x--;// Remove the lead 0
for(int i=m;i<len;i++)printf("%c",n[i]);
return 0;
}
The time limit : 1000 ms Memory limit : 65536 KB
Submission number : 25868 Passing number : 9164
【 Title Description 】
Enter a high precision positive integer n, Remove any of them s The rest of the numbers after the first number form a new positive integer according to the original left and right order . Programming for a given n and s, Find a scheme to make the new number of the remaining numbers minimum .
Output a new positive integer .(n No more than 240 position )
The input data do not need to be judged wrong .
【 Input 】
n
s
【 Output 】
The last remaining decimal .
【 sample input 】
175438
4
【 sample output 】
13
【 Algorithm analysis 】
greedy . loop s Time , Delete s A large number , The rest is the minimum .
【AC Code 】
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int N=340;
char n[N];
int s,len,m,x;
signed main()
{
scanf("%s%d",&n,&s);
x=len=strlen(n);
for(int i=1;i<=s;i++)
{
for(int j=0;j<len-1;j++)
if(n[j]>n[j+1])// If the current number is greater than the next number
{
for(int k=j;k<len-1;k++)n[k]=n[k+1];// Delete that number
break;// Out of the loop
}
len--;// length -1
}
while(n[m]=='0' and x>1)m++,x--;// Remove the lead 0
for(int i=m;i<len;i++)printf("%c",n[i]);
return 0;
}
边栏推荐
- 【STM32】STM32烧录程序后SWD无法识别器件的问题解决方法
- The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file
- Study summary of postgraduate entrance examination in November
- C#记录日志方法
- 无法打开内核设备“\\.\VMCIDev\VMX”: 操作成功完成。是否在安装 VMware Workstation 后重新引导? 模块“DevicePowerOn”启动失败。 未能启动虚拟机。
- 施努卡:机器人视觉抓取工作原理 机器视觉抓取
- leetcode-303:区域和检索 - 数组不可变
- BigDecimal数值比较
- [homework] 2022.7.6 write your own cal function
- php \n 换行无法输出
猜你喜欢
Mendeley--免费的文献管理工具,给论文自动插入参考文献
Several schemes of building hardware communication technology of Internet of things
P2788 数学1(math1)- 加减算式
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
使用Tansformer分割三维腹部多器官--UNETR实战
mysql插入数据创建触发器填充uuid字段值
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
P1223 排队接水/1319:【例6.1】排队接水
Inno setup packaging and signing Guide
555电路详解
随机推荐
JMeter loop controller and CSV data file settings are used together
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
Common shortcut keys in IDA
2022.7.5DAY597
Remote meter reading, switching on and off operation command
2022.7.3DAY595
The width of table is 4PX larger than that of tbody
Kotlin实现微信界面切换(Fragment练习)
Study summary of postgraduate entrance examination in November
Mendeley--免费的文献管理工具,给论文自动插入参考文献
Easyexcel read write simple to use
Socket通信原理和实践
深入理解Apache Hudi异步索引机制
Several schemes of building hardware communication technology of Internet of things
Deeply analyze the main contents of erc-4907 agreement and think about the significance of this agreement to NFT market liquidity!
P1031 [NOIP2002 提高组] 均分纸牌
Leetcode-304: two dimensional area and retrieval - matrix immutable
1323:【例6.5】活动选择
Study summary of postgraduate entrance examination in September
[牛客网刷题 Day6] JZ27 二叉树的镜像