当前位置:网站首页>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;
}

边栏推荐
- Multisim -- software related skills
- P2788 数学1(math1)- 加减算式
- Socket通信原理和实践
- Encrypt and decrypt stored procedures (SQL 2008/sql 2012)
- 字符串格式化
- I'd rather say simple problems a hundred times than do complex problems once
- Smart city construction based on GIS 3D visualization technology
- 施努卡:机器视觉定位技术 机器视觉定位原理
- BigDecimal数值比较
- 5个chrome简单实用的日常开发功能详解,赶快解锁让你提升更多效率!
猜你喜欢
随机推荐
Factorial implementation of large integer classes
Adb 实用命令(网络包、日志、调优相关)
宁愿把简单的问题说一百遍,也不把复杂的问题做一遍
使用 load_decathlon_datalist (MONAI)快速加载JSON数据
A small problem of bit field and symbol expansion
JMeter loop controller and CSV data file settings are used together
JMeter installation
CAS mechanism
MySQL insert data create trigger fill UUID field value
Sword finger offer 38 Arrangement of strings [no description written]
嵌入式工程师如何提高工作效率
leetcode-303:区域和检索 - 数组不可变
Talking about the return format in the log, encapsulation format handling, exception handling
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
5个chrome简单实用的日常开发功能详解,赶快解锁让你提升更多效率!
深入分析ERC-4907协议的主要内容,思考此协议对NFT市场流动性意义!
Summary of router development knowledge
Using U2 net deep network to realize -- certificate photo generation program
STM32 ADC和DMA