当前位置:网站首页>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;
}
边栏推荐
- Prototype object in ES6
- OpenGL glLightfv 函数的应用以及光源的相关知识
- Guid primary key
- IIC Basics
- 小程序跳转H5,配置业务域名经验教程
- Adb 实用命令(网络包、日志、调优相关)
- A small problem of bit field and symbol expansion
- 【acwing】789. Range of numbers (binary basis)
- 施努卡:机器人视觉抓取工作原理 机器视觉抓取
- Application of OpenGL gllightfv function and related knowledge of light source
猜你喜欢

【acwing】786. 第k个数

南航 PA3.1

The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file

JMeter about setting thread group and time

IIC Basics

The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.

Inno setup packaging and signing Guide

Use the fetch statement to obtain the repetition of the last row of cursor data

JMeter installation

【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
随机推荐
Socket通信原理和实践
[second on] [jeecgboot] modify paging parameters
BUUCTF---Reverse---reverse1
Trajectory planning for multi-robot systems: Methods and applications 综述阅读笔记
反射效率为什么低?
[homework] 2022.7.6 write your own cal function
Serial communication relay Modbus communication host computer debugging software tool project development case
2022.7.4DAY596
Slurm资源管理与作业调度系统安装配置
CAS机制
Multisim -- software related skills
The mobile terminal automatically adjusts the page content and font size by setting rem
【acwing】786. Number k
Experience sharing of software designers preparing for exams
多线程-异步编排
【剑指Offer】42. 栈的压入、弹出序列
Leetcode-304: two dimensional area and retrieval - matrix immutable
求方程ax^2+bx+c=0的根(C语言)
【acwing】786. 第k个数
Encrypt and decrypt stored procedures (SQL 2008/sql 2012)