Shredding Company

Linux新手必看:FinalShell连接不上?从检查IP到配置固定地址的完整排错指南 本文为Linux新手提供了FinalShell连接失败的完整排错指南,涵盖IP检查、SSH服务状态、防火墙配置和静态IP设置等关键步骤。通过详细的命令行操作和配置示例,帮助用户快速解决远程连接问题,提升Linux使用效率。 阅读详情
Problem 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 :< br>< br>tl num1< br>t2 num2< br>...< br>tn numn< br>0 0< br>< br>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.< br>< br>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.< br>< br>
 

Output
For each test case in the input, the corresponding output takes one of the following three types :< br>< br>sum part1 part2 ...< br>rejected< br>error< br>< br>In the first type, partj and sum have the following meaning :< br>< br>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.< br>< br>2.sum is the sum of the numbers after being shredded, i.e., sum = part1 + part2 +...< br>< br>Each number should be separated by one space.< br>The message error is printed if it is not possible to make any combination, and rejected if there is< br>more than one possible combination.< br>No extra characters including spaces are allowed at the beginning of each line, nor at the end of each line.< br>
 

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
  
 
题意;主要将的是一个数n,然后把这个数分成若干个,将这些分成若干的数字加起来,求出不超过n 的最大的数字和。如果最小的和都超过n,那么就error; 如果最大的数字和有两个,输出rejected ;
dfs,给了一个数,数字的第一个数字有两种选择,一种是单独分出去,一种是和后面的结合在组成一个新的数。
第一看感觉确实是复杂,分出两路来了,又发现代码写不出来,尤其的在不知道要用数组盛放数字的时候,放了好几天,今天知道室友跟我说用数组放数字的时候,理清思路,终于写出来了。

//dfs     
#if 0
#include<iostream>
#include<cstring>
using namespace std;
int n,a[10],t[10],end[10];        //a 开始的数组   t一直变换的数组 end最后结果的数组 
int D=0,num,lenth;
string s;

void dfs(int sum,int x,int p, int len)                  // 0 a[0] 0 0
{ 
	//cout<<"123000"<<endl; 
	
	if(sum>n) 
		return;
	if(p==s.size())                       //搜到底      
	{
		sum+=x;
		t[len]=x;
		/*for(int i=1; i<=len; i++)  
		{
			cout<<t[i]<<" ";
		}*/
		//cout<<endl<<"*************************"<<endl;  
		
		if(sum>n) 
			return;
			
		if(sum>D) 
		{
			D=sum;
			num=1;
			lenth=len;
			
			for(int i=1; i<=lenth; i++)
			{
				end[i]=t[i];
			}
		}
		else
		if(sum==D)
		{
			num=2;		
		}	
		return;
		
	}
	

		
		dfs(sum,x*10+a[p+1],p+1,len); 
		t[len]=x;
		len+=1; 
		dfs(sum+x,a[p+1],p+1,len);  	
		t[len]=0;
			
}

int main()
{
	while(cin>>n>>s)
	{
		if(n==0&&s=="0")
			break;
			
		D=0; num=0;
		memset(a,0,sizeof(a));
		memset(end,0,sizeof(end));
		memset(t,0,sizeof(t));
			
		for(int i=1; i<=s.size(); i++)
		{
			a[i]=s[i-1]-'0';
		}
	
	
			
		dfs(0,a[1],1,1);
	       
		if(num==0) 
		{
			cout<<"error"<<endl; 
		} 
		else 
		if(num==2)
		{
			cout<<"rejected"<<endl;
		}
		else
		{
			cout<<D;
			for(int i=1; i<=lenth; i++)
			{
				cout<<" "<<end[i];
			}
			cout<<endl;
		} 
	
	}

}
#endif 










Word2vec核心模型精讲:CBOW与Skip-gram Word2vec是Google提出的词向量模型,通过CBOW和Skip-gram两种神经网络架构将词汇映射到低维向量空间。CBOW通过上下文预测中心词,训练速度快但高频词表现更好;Skip-gram则相反,通过中心词预测上下文,适合处理生僻词。为解决softmax计算效率问题,Word2vec引入基于哈夫曼树的Hierarchical Softmax优化技术,将复杂度从O(V)降至O(logV)。文章详细解析了两种模型的原理差异,并演示了哈夫曼树的构造过程及其在词向量训练中的关键作用,这种结合词频的优 阅读详情

相关推荐

FPGA控制DDR读写(AXI4总线接口)

FPGA控制DDR读写

qq_42712308的博客 1万+

POJ 1416 Shredding Company(简单DFS)

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

叶孤心的专栏 855

NHANES数据库实战:数据合并与加权分析技巧

本文详细解析了NHANES数据库实战中的核心技巧,重点阐述了数据合并与加权分析的正确方法。通过两个具体案例,手把手指导如何从数据下载、合并、权重计算到使用R语言survey包进行加权统计分析,避免因忽略复杂抽样设计而导致的研究偏倚,确保分析结果的准确性与可发表性。

weixin_29057065的博客 585

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

岁月流风、、 1505

TMS320F28377D的sys/bios双核工程配置详解——从零搭建到RAM优化

本文详细解析了TMS320F28377D双核系统在sys/bios环境下的工程配置与RAM优化策略。从开发环境搭建、SYS/BIOS工程创建到双核CMD文件配置,提供了实战技巧和常见问题解决方案,帮助开发者高效实现电力电子控制系统中的双核协作与性能优化。

weixin_28292761的博客 600

MOOS-ivp 实验一 MOOS软件的安装与执行

MOOS-ivp实验一 实验一步骤总结 文章目录MOOS-ivp实验一前言一、实验一1.下载软件2.安装必要的插件3.安装后检查4.路径添加5.执行示例文件总结 前言 在moos学习过程中,我觉得最好把学习的每一步骤都总结一下,方便日后进行回顾。moos官网设置了十八个实验,涉及到了moos的各个方面,完成这些实验也是moos入门的好办法。 一、实验一 实验一主要内容仅仅是软件的安装,仅仅这一步就花费了我接近两天的时间。主要问题发生在linux系统的配置问题上。 1.下载软件 svn co https:

weixin_44151170的博客 6669

Shredding Company (dfs)

  Problem 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...

a1046765624的博客 1563

【生信】全基因组测序(WGS)

1、全基因组测序(WGS) 的定义 2、GWS流程 2.1准备工作——分析软件 2.2原始数据质控 2.3数据预处理 2.4变异检测

weixin_40695088的博客 4万+

POJ.1416 Shredding Company (DFS)

POJ.1416 Shredding Company [从零开始DFS(8)]点我挑战题目题意分析给出一个目标数字n和一串数字序列s,要求切割序列s为若干数字段s1,s2,s3……sn,最后求出最大的 不超过目标数字n的 序列s切割方式,和这些字段的和。若对于最大的数字有多种切割方式,则输出rejected;若没有这样的切割方式,则输出error。直接对给出的数字串操作有些不方便,我们不妨想想挡板

Pengwill's Blog 502

专为AI打造的浏览器:内存占用仅为Chrome的1/9、比Chrome快11倍(Docker部署教程,支持飞牛nas等服务器部署)

🚀 专为AI打造的无头浏览器来了! 用Zig从零构建,内存仅Chrome的1/9,速度快11倍,原生CDP协议支持Docker部署,适合爬虫、自动化测试和AI代理应用。✨

XiaoqiangClub的博客 732

开关电源和线性电源Multisim电路仿真实验汇总——硬件工程师笔记

本文系统介绍了稳压电源的基础知识与应用实验。首先阐述了稳压电源的定义与类型,包括线性稳压电源(如LM7805/7905)和开关稳压电源(降压/升压/升降压式)的工作原理、参数特点及优劣势。随后详细讲解了各类稳压电源的实验设计,如线性稳压电源的电路实现、开关稳压电源的PWM控制方法等。最后汇总了硬件工程师相关的笔试面试资源,涵盖器件知识、电路仿真、企业真题等内容。全文结合理论分析与Multisim仿真,为电子工程学习者提供了稳压电源的实用技术参考。

XU157303764的博客 1640

DFS——《算法竞赛入门到进阶》(N皇后问题,Shredding Company,Sudoku和Channel Allocation问题详解)

DFS 从初始状态出发,下一步可能有多种状态;选其中一个状态深入,到达新的状态;直到无法继续深入,回退到前一步,转移到其他状态,然后再深入下去。最后,遍历完所有可以到达的状态,并得到最终的解。 题目 N皇后问题(涉及回溯和剪枝) 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法。 Input 共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束

weixin_54248223的博客 699

读懂 SAP Fiori Administration Catalogs:从管理员入口、权限编排到 Spaces 和 Pages 的落地实践

SAP Fiori 管理员目录的核心价值在于为系统配置提供标准化入口,解决权限与展示分离的问题。随着 SAP_UI 7.55 版本更新,SAP_FLP_ADMIN 角色整合了关键管理工具(如 Launchpad Designer、Content Manager),并通过 Business Catalog 和 Space 的协同作用,确保管理员既能访问配置工具,又能直观查看相关功能入口。项目实施中需注意配置层级(系统级/客户端级)的选择,以及多人协作时的数据同步问题,以提升交付效率。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 195

poj1416 Shredding Company

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

keshuqi的博客 608

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

POJ1416 Shredding Company

题目链接:http://poj.org/problem?id=1416 【分析】     水题不多说......直接暴力。 【代码】 #include #include #include using namespace std; int a[8],v[8][8]; int n,target,num; int d[8],fnd[8],fp; int ans,ansti

Zarxdy34 804

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

HDU1539 Shredding Company

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 Shred

zf______的博客 1183

SAP B1中文培訓教材_SDK

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

POJ 1416 Shredding Company

这道题是道水题,不要介意神马前导零之类的,没影响。 题目大意: 公司现在要发明一种新的碎纸机,要求新的碎纸机能够把纸条上的数字切成最接近而不超过target值。比如,target的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1、2、34、6。因为这样所得到的和43 (= 1 + 2 + 34 + 6) 是所有可能中最接近而不超过50的。(比如1, 23, 4, 和

脑残的孩子只有慢慢学。。 4537

POJ 1416 Shredding Company【dfs入门】

题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit:1000MS Memory Limit:10000K Total Submissions:6860 Accepted:3710 Description You have just been pu...

weixin_30311605的博客 157

hdu 1539 Shredding Company

Shredding Company Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 250    Accepted Submission(s): 64 Problem Description You have

To be what you what to be! 1207

poj 1416 Shredding Company

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

100days 678

1416 Shredding Company

这道题就是搜索,大家懂的!#include #include char str[7]; int numlist[7],list[7],n,sum,len,flag1,flag2,level; int StrToInt(char *str,int len) //字符串转整型 { int i,sum = 0; for(i = 0;i =len) { if( (n-num)

onealwjwjwjwj的专栏 441

【POJ1416】Shredding Company

本题传送门 本题知识点:深度优先搜索 + 回溯 本题题意很简单,就是有一条位数不超过6的数字纸条,问你怎么剪这纸条,使得得到的纸条的值的总和最接近目标值(总和不能超过目标值)。 比如第一个样例 50 12346 12346可以剪成 1 2 3 4 6(总和16);12 34 6(总和52)等,其中最接近且不大于目标值的就是剪成1 2 34 6,总和是43,所以输出 43 1 2 34 6...

LT4585的博客 313

poj1416——Shredding Company

题目大意:搞一个碎纸机,一张卡片上有几个数字,使剪碎后每张卡片的数字之和最接近目标数字并且不超过它,有三种特殊情况:如果卡片上数字是目标数字本身,就不用切碎了;如果怎么剪都没有解(比如剪成最小的都会使和超过目标数字),则输出error;如果有多个解,则输出rejected 输入:(有多个case,输入以0 0结束)             第i个case的目标数字 第i个case卡片上的数字(

tzyshiwolaogongya的博客 262
上一篇: 8.8训练日记
下一篇: Wormholes(负权回路)
Joined
博客等级 码龄10年 19粉丝 134原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值