L - Shredding Company

POJ1416-Shredding Company 北大POJ1416-Shredding Company 解题报告+AC代码 立即下载
L - Shredding Company
Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

Description

You have just been put in charge of developing a new shredder for the Shredding Company Although a "normal" shredder would just shred sheets of paper into little pieces so that the contents would become unreadable, this new shredder needs to have the following unusual basic characteristics. 

1.The shredder takes as input a target number and a sheet of paper with a number written on it. 

2.It shreds (or cuts) the sheet into pieces each of which has one or more digits on it. 

3.The sum of the numbers written on each piece is the closest possible number to the target number, without going over it. 

For example, suppose that the target number is 50, and the sheet of paper has the number 12346. The shredder would cut the sheet into four pieces, where one piece has 1, another has 2, the third has 34, and the fourth has 6. This is because their sum 43 (= 1 + 2 + 34 + 6) is closest to the target number 50 of all possible combinations without going over 50. For example, a combination where the pieces are 1, 23, 4, and 6 is not valid, because the sum of this combination 34 (= 1 + 23 + 4 + 6) is less than the above combination's 43. The combination of 12, 34, and 6 is not valid either, because the sum 52 (= 12 + 34 + 6) is greater than the target number of 50. 
 
Figure 1. Shredding a sheet of paper having the number 12346 when the target number is 50


There are also three special rules : 

1.If the target number is the same as the number on the sheet of paper, then the paper is not cut. 

For example, if the target number is 100 and the number on the sheet of paper is also 100, then 

the paper is not cut. 

2.If it is not possible to make any combination whose sum is less than or equal to the target number, then error is printed on a display. For example, if the target number is 1 and the number on the sheet of paper is 123, it is not possible to make any valid combination, as the combination with the smallest possible sum is 1, 2, 3. The sum for this combination is 6, which is greater than the target number, and thus error is printed. 

3.If there is more than one possible combination where the sum is closest to the target number without going over it, then rejected is printed on a display. For example, if the target number is 15, and the number on the sheet of paper is 111, then there are two possible combinations with the highest possible sum of 12: (a) 1 and 11 and (b) 11 and 1; thus rejected is printed. In order to develop such a shredder, you have decided to first make a simple program that would simulate the above characteristics and rules. Given two numbers, where the first is the target number and the second is the number on the sheet of paper to be shredded, you need to figure out how the shredder should "cut up" the second number. 

Input

The input consists of several test cases, each on one line, as follows : 

tl num1 
t2 num2 
... 
tn numn 
0 0 

Each test case consists of the following two positive integers, which are separated by one space : (1) the first integer (ti above) is the target number, (2) the second integer (numi above) is the number that is on the paper to be shredded. 

Neither integers may have a 0 as the first digit, e.g., 123 is allowed but 0123 is not. You may assume that both integers are at most 6 digits in length. A line consisting of two zeros signals the end of the input. 

Output

For each test case in the input, the corresponding output takes one of the following three types : 

sum part1 part2 ... 
rejected 
error 

In the first type, partj and sum have the following meaning : 

1.Each partj is a number on one piece of shredded paper. The order of partj corresponds to the order of the original digits on the sheet of paper. 

2.sum is the sum of the numbers after being shredded, i.e., sum = part1 + part2 +... 

Each number should be separated by one space. 
The message error is printed if it is not possible to make any combination, and rejected if there is 
more than one possible combination. 
No extra characters including spaces are allowed at the beginning of each line, nor at the end of each line. 

Sample Input

50 12346
376 144139
927438 927438
18 3312
9 3142
25 1299
111 33333
103 862150
6 1104
0 0

Sample Output

43 1 2 34 6
283 144 139
927438 927438
18 3 3 12
error
21 1 2 9 9
rejected
103 86 2 15 0
rejected

泰凌微8258入门教程——导读 基于泰凌微TLSR8258 Bluetooth® SIG Mesh 的入门系列教程 阅读详情

相关推荐

RK3588 InsightFace人脸识别移植及精度测试全解析

本文详细介绍了如何在RK3588平台上移植InsightFace人脸识别模型并进行精度验证。通过PyTorch转ONNX、ONNX转RKNN量化模型的关键步骤,实现了INT8量化模型的部署。测试数据显示,该模型在LFW数据集上达到99.43%的准确率(接近官方99.52%),推理时间仅14.23ms。ROC曲线和相似度分布图表明模型区分能力优秀,AUC超过0.99,满足实际应用需求。文中还详解了量化原理、环境搭建和测试方法,为边缘设备部署人脸识别提供了完整解决方案。

Hi20240217的博客 3662

DFS学习笔记-POJ1416 Shredding Company

关于初学者对DFS的一些浅要理解,以poj1416为例

ex_voda的博客 726

在 STM32CubeIDE 中针对 STM32F407 移植 ThreadX

在 STM32CubeIDE 中针对 STM32F407 移植 ThreadX,不依赖盗版破解的Keil MDK、IAR等软件。

wangyuewu08的博客 3374

poj1416的题解

#include<iostream> #include<cmath> #include <cstring> using namespace std; int getlen(int n) //得到n的位长度 { if (n < 10) return 1; else if (n < 100) retu...

xiaozhou163的博客 294

软件工程:数据字典

数据字典

永远怀着至诚之心拥抱世界 4273

【仿真】Carla Python API实战:从零搭建自动驾驶测试环境

本文详细介绍了如何使用Carla Python API从零搭建自动驾驶测试环境。通过Carla仿真平台,开发者可以构建高度逼真的城市环境和车辆物理模型,利用Python API实现传感器配置、数据采集、场景构建及自动驾驶算法集成。文章还分享了实际项目中的调试技巧和性能优化经验,帮助读者快速掌握自动驾驶仿真测试的核心技术。

weixin_29050513的博客 213

noi.openjudge.cn 题目用到的头文件

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { return 0; }

sflsgfs的专栏 2350

ROS2通过ros2_socketcan实现CAN总线高效数据过滤与多节点通信

本文详细解析了ROS2通过ros2_socketcan实现CAN总线高效数据过滤与多节点通信的技术方案。文章重点探讨了CanFilterList的工作原理、多过滤器组合使用及动态配置策略,有效解决了工业应用中CAN总线数据过载问题,显著降低了CPU负载并提升了系统实时性。

n4o5p6q7r的博客 215

POJ-1416 Shredding Company 解题报告

Description You have just been put in charge of developing a new shredder for the Shredding Company Although a "normal" shredder would just shred sheets of paper into little pieces so that the cont

岁月流风、、 1504

最新Python爬虫实战(入门爬虫篇)——案例7:电影网站电影数据采集(详细爬虫思路截图+抓包动图演示+完整爬虫代码+详细注释)

本次案例通过Python爬虫技术,成功实现了对某电影网站Top250多页电影详细信息的批量爬取与Excel保存。代码采用模块化设计,包含分页请求构造、XPath+正则提取结构化信息、Excel数据持久化保存等完整流程。通过配置User-Agent等请求头信息,有效模拟浏览器行为以绕过豆瓣基础反爬策略。整个爬虫逻辑遵循"分页遍历 → 请求页面 → 解析HTML → 提取电影信息 → 保存到Excel"的标准流程,与主流静态网站爬取范式高度一致。

努力让自己发光,对的人才能迎着光而来 11万+

卫朋:IPD流程落地——产品计划阶段拆解

IPD计划阶段拆解

产品线负责人 956

poj1416

题意: 要求碎纸机能够把纸条上的数字切成一些片段,这些片段的和最接近而不超过所给的值tar,第一个样例,tar的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1、2、34、6。因为这样所得到的和43 (= 1 + 2 + 34 + 6) 是所有可能中最接近而不超过50的。 三个要点: 1、如果tar的值等于纸条上的值,则不切。 2、如果没有办法把纸条上的数字切成小于

emmmmmm 2638

晶体管-二极管三极管MOS管选型参数总结

二极管三极管和MOS管,是电路中常用的控制电流电压的基本电子元器件。电路世界中晶体管的选型,需要考虑的参数多种多样,这些参数的选择会直接影响到电路的性能、稳定性、成本等多个方面。本文对二极管三极管和MOS管的选型参数进行详细介绍并总结。

fydar的博客 884

Shredding Company (dfs)

Shredding Company Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submission(s) : 37   Accepted Submission(s) : 17 Problem Description You have just been pu

sdau20163940的博客 1875

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

poj 1416 Shredding Company(dfs)

参考题解:http://blog.youkuaiyun.com/lyy289065406/article/details/6647969 题意和思路在题解都有,思路很简单,奈何我写了好久愣是没实现出来。。。#include <iostream> #include <cmath> #include <cstring> using namespace std;int aim,result,path,sum,p;

梦幻的蔷薇色 368

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

POJ 1416 Shredding Company(DFS + 打印最优解)

题意: 给定一个target数字,一个num,要求分解num,使得num被分解后所得的各数之和小于并且最接近target,这个和就是最优解。 若无最优解输出error,若同时多个最优解,则输出rejected。 思路: 1. 深搜的过程中有一个技巧点:对于第 i 个数字,是否会和后面的数字进行组合展开讨论。cur 代表前面待组合的值,sum 代表当前已经确定要分割的数字的和; ...

weixin_30940783的博客 91

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

poj 1416 dfs 回溯

#include #include using namespace std; long int path,p,temp,aim; // path记录对应的一种划分,temp记录最大值个数 个人觉得temp的c long int sum,result; int he(char s[],int i) //前i位的和 { int sum1=0,j; for(j=0;j<i;j++)

leo_cuiyiming的专栏 379

POJ 1416 DFS 加简单剪枝

剪枝的条件很明确,如果现在的 前面已经断开的纸带的和与当前纸带的和大于目标值,就不用向下搜索了。 注意一个细节是,第一个只能加到当前纸带上 其实这种题还是一个表示状态的问题 dfs(sum,cur,p) 表示前面的和 当前纸带的和 当前走到了第几个 这样足够清晰的描述问题了 #include #include #include #include #include

用心一也 606

POJ1416 DFS+剪枝

[题目大意]:      公司现在要发明一种新的碎纸机,要求新的碎纸机能够把纸条上的数字切成最接近而不超过target值。比如,target的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1、2、34、6。因为这样所得到的和43 (= 1 + 2 + 34 + 6) 是所有可能中最接近而不超过50的。(比如1, 23, 4, 和6 就不可以,因为它们的和不如43接近50,而1

cumt_wangxiang的博客 420

POJ-1416-Shredding Company

这个题也是DFS题。 大意是说给你2个数,第一个为目标数,第二个为你要处理的数,要求将第二个数进行分割,使得各部分之和最接近目标数且必须小于目标数。 其实一个DFS就可以做出来,中间注意下数中的0的特殊处理,因为0也可以占位的,输出rejecter需要注意下 直接代码吧: #include #include #include using namespace std; long long g

z309241990的专栏 716

纸片粉碎 POJ1416 暴搜 + 枚举

纸片粉碎 POJ1416 暴搜 + 枚举 本题实质是一个单纯的DFS,而且也不用剪枝,直接暴搜 + 枚举即可。仔细分析本题,可以对递归算法的实现有更深的理解。特别能帮助理解,递归算法层层深入,然后可能回溯返回的过程。如何保存递归路径也是经常会遇到的问题。

sj13051180的专栏 1万+

POJ 1416 暴搜

Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4760 Accepted: 2746 DescriptionYou have just been put in charge of developing a new shredder for the Shredding C

仰望天空 405

POJ 1416 Shredding Company (DFS+构造)

Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4398 Accepted: 2520 Description You have just been put in charge of developing a new shre

Tc的专栏 1394

Poj1416: Shredding Company

1.只能说很遗憾,自己也不知道哪里错了。但就是WA。所有测试数据包括别人给的都是对的。包括自己随便写也是。但是就是WA   2.逻辑很重要。原来自己用的step而不是start和end,就错的离谱。 3. 另外,要单独有个path记录,每次得到最短路径之后都要new一个新的list记下来。因为还有回溯。 4. 还有关于重复最优解就拒绝。有个计数器就可以了。 5. 大体思路其实很简单,就

kaka0930的博客 1280

poj 1416

题目大意:      将一串数字分成若干个部分  ( 例如12346) 求其中和不超过数字 n (例50) 的最大值。      比如说 12346  可以分成 12+34+6 = 52      1+2+34+6 = 43      其中43满足,52不满足,因为不允许超过。 注意:  1、123 可以拆成 1+23  12+3  ,但13+2是不允许的。    21+3,3

wodasini的专栏 396

[DFS]poj1416

题意: 如果输入的串分割后的和最小都比Target大,那就输出error. 如果有多种结果一样,那么就输出rejected. 否则,输出最大的和 和分别是哪些子串。这个题都是整数,所以比较简单。直接搜索所有的情况就好了,还有一点是打印路径,一般可以用path[]或者pre[]的数组表示,但是这里数据有点大我就用的map水过了。。#include <cstdio> #include <cstri

zylm的专栏 672
上一篇: K - Network Saboteur
下一篇: M - Sudoku
CSUST_ACM
博客等级 码龄15年 42粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值