当前位置:网站首页>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;
}
边栏推荐
- [dai6] mirror image of JZ27 binary tree
- 【二开】【JeecgBoot】修改分页参数
- [email protected] can help us get the log object quickly
- [STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program
- Slurm资源管理与作业调度系统安装配置
- 串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
- Multisim--软件相关使用技巧
- BigDecimal value comparison
- Guid primary key
- 电表远程抄表拉合闸操作命令指令
猜你喜欢

leetcode-560:和为 K 的子数组

Inno Setup 打包及签名指南
![[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program](/img/03/41bb3870b9a6c2ee66099abac08eb3.png)
[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program

对存储过程进行加密和解密(SQL 2008/SQL 2012)

Talking about the return format in the log, encapsulation format handling, exception handling

Using U2 net deep network to realize -- certificate photo generation program

IO model review

Guide de signature du Code Appx

BUUCTF---Reverse---reverse1

【acwing】789. 数的范围(二分基础)
随机推荐
Appx code signing Guide
Jump to the mobile terminal page or PC terminal page according to the device information
JMeter loop controller and CSV data file settings are used together
【华为机试真题详解】高矮个子排队
IO模型复习
深入分析ERC-4907协议的主要内容,思考此协议对NFT市场流动性意义!
Use the fetch statement to obtain the repetition of the last row of cursor data
Study summary of postgraduate entrance examination in October
555电路详解
串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
[higherhrnet] higherhrnet detailed heat map regression code of higherhrnet
成为优秀的TS体操高手 之 TS 类型体操前置知识储备
ThreadLocal会用可不够
A small problem of bit field and symbol expansion
Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master
Common shortcut keys in IDA
深入理解Apache Hudi异步索引机制
CAS机制
电表远程抄表拉合闸操作命令指令
Mendeley--免费的文献管理工具,给论文自动插入参考文献