当前位置:网站首页>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;
}
边栏推荐
- P1031 [NOIP2002 提高组] 均分纸牌
- Leetcode-560: subarray with sum K
- About hzero resource error (groovy.lang.missingpropertyexception: no such property: weight for class)
- 0x0fa23729 (vcruntime140d.dll) (in classes and objects - encapsulation.Exe) exception thrown (resolved)
- 1323:【例6.5】活动选择
- C#记录日志方法
- Why is the reflection efficiency low?
- Kotlin realizes wechat interface switching (fragment exercise)
- Adb 实用命令(网络包、日志、调优相关)
- 对word2vec的一些浅层理解
猜你喜欢

JMeter installation

Some superficial understanding of word2vec

【STM32】STM32烧录程序后SWD无法识别器件的问题解决方法

基于HPC场景的集群任务调度系统LSF/SGE/Slurm/PBS

1324:【例6.6】整数区间

Several schemes of building hardware communication technology of Internet of things

Trajectory planning for multi-robot systems: Methods and applications 综述阅读笔记

Some properties of leetcode139 Yang Hui triangle

Review of the losers in the postgraduate entrance examination

Use the fetch statement to obtain the repetition of the last row of cursor data
随机推荐
[homework] 2022.7.6 write your own cal function
01 use function to approximate cosine function (15 points)
Prototype object in ES6
JS实现链式调用
【acwing】786. Number k
无法打开内核设备“\\.\VMCIDev\VMX”: 操作成功完成。是否在安装 VMware Workstation 后重新引导? 模块“DevicePowerOn”启动失败。 未能启动虚拟机。
Mendeley--免费的文献管理工具,给论文自动插入参考文献
电表远程抄表拉合闸操作命令指令
IPv4 socket address structure
Study summary of postgraduate entrance examination in July
Prototype and prototype chain
2022.7.5DAY597
Several schemes of building hardware communication technology of Internet of things
Appx代碼簽名指南
[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program
Leetcode-303: region and retrieval - array immutable
[dai6] mirror image of JZ27 binary tree
Inno setup packaging and signing Guide
HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。
The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.