HDU 5933 - ArcSoft's Office Rearrangement (贪心)

Silvaco Atlas从头开始(四)——定义材料参数和模型 这部分是关于定义材料参数和模型。 阅读详情

ArcSoft's Office Rearrangement

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2455    Accepted Submission(s): 826


Problem Description
ArcSoft, Inc. is a leading global professional computer photography and computer vision technology company.

There are  N  working blocks in ArcSoft company, which form a straight line. The CEO of ArcSoft thinks that every block should have equal number of employees, so he wants to re-arrange the current blocks into  K  new blocks by the following two operations:

- merge two neighbor blocks into a new block, and the new block's size is the sum of two old blocks'.
- split one block into two new blocks, and you can assign the size of each block, but the sum should be equal to the old block.

Now the CEO wants to know the  minimum operations to re-arrange current blocks into  K  block with equal size, please help him.
 

Input
First line contains an integer  T , which indicates the number of test cases.

Every test case begins with one line which two integers  N  and  K , which is the number of old blocks and new blocks.

The second line contains  N  numbers  a1 ,  a2 ,  ⋯ ,  aN , indicating the size of current blocks.

Limits
1≤T≤100
1≤N≤105
1≤K≤105
1≤ai≤105
 

Output
For every test case, you should output  'Case #x: y', where  x indicates the case number and counts from  1 and  y is the minimum operations.

If the CEO can't re-arrange  K  new blocks with equal size,  y equals  -1.
 

Sample Input
  
3 1 3 14 3 1 2 3 4 3 6 1 2 3
 

Sample Output
  
Case #1: -1 Case #2: 2 Case #3: 3
 

Source
 

题意:
给你n个数,问你能不能平均分成k个数,问你操作次数最少几次。
操作1:合并【相邻】的两个数,操作2:把一个数拆成2个数。

POINT:
aim=sum/k。
一开始没看到相邻,做了3个小时。
操作是,从第一个开始便利,大于aim就切,剩余的合到下一个。就好了。


#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <queue>
#include <functional>
using namespace std;
#define LL long long
const LL maxn = 1e5 + 6;
LL a[maxn];
int main()
{
	LL T, cas = 0;
	scanf("%lld", &T);
	while (T--) {
		LL n, k; scanf("%lld %lld", &n, &k);
		LL sum = 0;
		for (LL i = 1; i <= n; i++) {
			scanf("%lld", &a[i]);
			sum += a[i];
		}
		if (sum%k != 0) {
			printf("Case #%lld: -1\n", ++cas);
			continue;
		}
		LL aim = sum / k;
		LL ans = 0;
		for (LL i = 1; i<n; i++) {
			if (a[i]>aim) {
				LL num = a[i] / aim;
				ans += num;
				if (a[i] % aim == 0) ans--;
				else
					ans++;
				a[i] %= aim;
				a[i + 1] += a[i];
			}
			else if (a[i]<aim) {
				ans++;
				a[i + 1] += a[i];
			}
		}
		ans += a[n] / aim - 1;
		printf("Case #%lld: %lld\n", ++cas, ans);


	}


	return 0;
}


AI PPT时代来了:十个GitHub高热度Skill技能包全拆解 随着人工智能与办公自动化的深度融合,传统PPT制作正被一种新的技术范式所颠覆——Skill技能包。所谓Skill,本质是将优秀PPT背后的设计方法论、叙事逻辑与视觉规范固化为可复用的规则文件,AI通过加载这些协议,即可摆脱模板套用的机械输出,实现从内容构思到版式生成的全流程自动化。这一趋势在GitHub上迅速升温,得益于Claude Skills等Agent规范与MCP协议的成熟,让AI能直接调用渲染引擎,打通思考与执行。对于产品经理、教师、创业者等高频制作PPT的群体,掌握这类技能包意味着效率的数量级提升 阅读详情

相关推荐

OpenStack 8 节点生产级高可用(HA)集群实施文档

本文详细介绍了生产级高可用OpenStack集群的架构设计与实施方案。通过采用3节点控制集群(HAProxy+Keepalived)、2节点计算资源池和3节点Ceph分布式存储,实现了控制平面、计算资源和存储系统三个层面的高可用。方案重点阐述了VIP漂移、MariaDB Galera集群、RabbitMQ镜像队列等关键组件的配置方法,并提供了完整的部署流程和故障验证方案。该架构确保任意单节点故障不会影响平台整体可用性,满足生产环境对稳定性、扩展性和可维护性的要求,为构建无单点故障的OpenStack生产环境

彭大帅的博客 788

hdu 5933 ArcSoft's Office Rearrangement(贪心)

Problem Description ArcSoft, Inc. is a leading global professional computer photography and computer vision technology company.There are N working blocks in ArcSoft company, which form a straight line

HJ 870

【实战】ESP32 + LN298N 实现电动推杆的闭环位置伺服控制

本文详细介绍了如何使用ESP32微控制器和LN298N电机驱动模块,为普通电动推杆增加编码器反馈,实现精准的闭环位置伺服控制。文章从硬件选型与接线讲起,深入解析了编码器四倍频计数原理与位置换算,并重点阐述了PID控制算法的核心思想、代码实现及参数整定方法,旨在帮助读者从零构建一个反应迅速、定位精准的智能执行器系统。

weixin_29195615的博客 327

HDU5933ArcSoft's Office Rearrangement(模拟)

ArcSoft’s Office RearrangementTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 422 Accepted Submission(s): 199Problem Description ArcSoft, I

妍恐龙的博客....^~^眼熟我 675

RTDETR多模态融合实战:基于注意力机制的红外与可见光目标检测优化

本文深入探讨了基于RTDETR模型的红外与可见光多模态目标检测优化方案。针对复杂光照下的检测难题,文章提出并实战演示了如何利用注意力机制(如SimAM与交叉注意力)实现RGB与IR特征的智能动态融合,从而构建更鲁棒的“全天候”检测系统,有效提升安防、自动驾驶等场景在夜间及恶劣天气下的检测精度与可靠性。

weixin_29083373的博客 197

JavaSwing_1.1: FlowLayout(流式布局)

FlowLayout,流式布局管理器。按水平方向依次排列放置组件,排满一行,换下一行继续排列。

谢TS的博客 7万+

2016年中国大学生程序设计竞赛(杭州) A ArcSoft's Office Rearrangement(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5933 ArcSoft’s Office RearrangementTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 288 Accep

linlinsong—ACM界蒟水! 742

华为OD机考双机位C卷 - 最左侧冗余覆盖子串 (Java)

华为OD机考双机位C卷 - 最左侧冗余覆盖子串 (Java), 提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。

算法大师! 61

ArcSoft's Office Rearrangement(贪心)

ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description A

spark__s的博客 1028

基于Jeecgboot3.8.1的vue3版本前后端分离的flowable流程管理平台

基于Jeecgboot3.8.1的vue3版本前后端分离的flowable流程管理平台

宁波阿成的博客 1547

Arduino与Proteus仿真实例-LCD2004-I2C(PCF8574)驱动仿真

LCD2004-I2C(PCF8574)驱动仿真 PCF8574/74A 通过两线双向 I2C 总线(串行时钟 (SCL)、串行数据 (SDA))提供通用远程 I/O 扩展。 LCD2004,即2004字符型液晶显示器,是一种点阵模块,用于显示字母、数字、字符等。 它由 5x8 个点阵位置组成; 每个位置可以显示一个字符。 两个字符之间有一个点间距,行之间有一个空格,从而将字符和行分开。 模型 2004 表示它显示 4 行,每行 20 个字符。 在前面的实例中对PCF8574和LCD2004的已经做了详细介

视觉与物联智能 1168

HDU 5933 ArcSoft's Office Rearrangement (思维)

ArcSoft’s Office Rearrangement Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4028 Accepted Submission(s): 1260 Problem Description ArcSoft...

ftx456789的博客 333

matlab 点云可视化(1)——pcshow()函数可视化单个点云

matlab可视化单个点云常用方法汇总。

点云侠的博客 5365

hdu5933 ArcSoft's Office Rearrangement 贪心

ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 136    Accepted Submission(s): 65 Problem Description

kyoma的博客 945

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

HDU 5933 ArcSoft's Office Rearrangement(贪心)

Problem Description ArcSoft, Inc. is a leading global professional computer photography and computer vision technology company.There are N working blocks in ArcSoft company, which form a straight line

henuzxy 298

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

HDU 5933 ArcSoft's Office Rearrangement 贪心

题目链接:https://vjudge.net/problem/HDU-5933 题解:因为拆分合并只需要考虑相邻的区域就好,所以不够就合并,多了就拆分。 #include #define maxn 100010 #define ll long long using namespace std; int main() { int T; scanf("%d",&T); i

DlPF_C的博客 389

【HDU 5933】 ArcSoft's Office Rearrangement 【贪心】

题意:有n堆石子 有两种操作 1合并相邻两堆 2把一堆分成两堆(大小任意和为一堆的大小)  问将这n堆石子分成等量的k堆 最多需要多少次操作题解:首先,所有堆石子之和必须是k的整数倍然后,贪心的去想,如果一个石子堆不是k的整数倍,那么他必须要和别的石子合并之后才能形成k的整数倍所以我们每次从前往后求和,到和为k的整数倍停止,然后将合并后的石子分成目标大小 这里最少分的次数为(能分成的堆数-1)次上...

sjtsjt709的博客 309

hdu5933-贪心&思维&细节-ArcSoft's Office Rearrangement

https://vjudge.net/problem/542123/origin 错在没有用 longlong。。真不知道咋想的。。以为数据范围只有1e5。 但是加起来有很多啊。 开始以为只有100个数,可是明明自己开的1e5.. 给定一个数组,你有两种操作 1 把这个数组中的一个数非为两份,大小自己定,但是总和要等于原来的大小。 2 把相邻的两个合起来。 问你最少的操作数,可以把这m

天与云与山与水 230

2016 CCPC Hangzhou Onsite A - ArcSoft's Office Rearrangement(HDU 5933) (贪心,模拟)

ArcSoft, Inc. is a leading global professional computer photography and computer vision technology company.  There are NN working blocks in ArcSoft company, which form a straight line. The CEO of

Sizaif's 小屋 670

hdu5933ArcSoft's Office Rearrangement

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5933 题意:将给定的n堆员工重新平均分成k堆,每次只能合并相邻两堆或者将一堆分成相邻的两堆,不可行输出-1或者输出最小操作数。 分析:很明显只需要从左往右模拟即可,比平均值多就分出一堆,小了就合并到下一堆。 代码: #include #include #include #include #incl

Fsss 613

HDU 5933 ArcSoft's Office Rearrangement

贪心: 考虑第一个数字,如果它比平均数少,那么只能由它右边相邻的那个提供,如果它比平均数多,也只能通过右边的分出去。所以只要从左到右贪心一遍即可 【代码】 #include #include #include #include #include #include #include #include #include #include #include #incl

卡尔 795

hdu 5933 ArcSoft's Office Rearrangement

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5933 题目描述:   Problem Description ArcSoft, Inc. is a leading global professional computer photography and computer vision technology company. There ar...

逍遥 466

HDU5933 ArcSoft's Office Rearrangement (模拟) 2016年中国大学生程序设计竞赛(杭州)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5933 题目大意:有n个块,每个块大小为ai,现在要变成k个块,每个块大小一样,现在有两个操作:把一个块分割成任意两个大小的块,或者将相邻的两个块合并,问最小操作数。 解题思路:遍历一遍每个块,然后分类讨论就好了……水题,注意long long 的坑。 /* *******

blanKey的博客 639

HDU-5933-ArcSoft's Office Rearrangement

ACM模版描述题解给定 NN 个数要求划分为 KK 份,一共有两种操作,一种是将相邻两数合并,一种是将一个数拆开两部分。很明显的贪心模拟,这场比赛好像比较钟爱贪心模拟,可是这个题好坑,因为题目中约定的数据不可能超过 intint,却挂了,必须使用 longlonglong long 才行。代码#include <iostream> #include <cstdio> #include <queue>

逐梦者 482

「国庆训练」ArcSoft's Office Rearrangement(HDU-5933)

题目与分析 题解见https://blog.csdn.net/cmershen/article/details/53200922。 训练赛场上我们写出来了——在4小时50分钟的时候。。。激情补题啊。。。问题是这就是个尬模,我赛场上的写法和这个差不多。。。然后疯狂wa。。。 最后AC的是换了个写法。。。。然后现在我再重头写我都一股子蛋疼,特么找不到问题在哪里是真的骚,以后多训练才是王道。(之后回顾的...

weixin_30823001的博客 97

[HDOJ5933]ArcSoft's Office Rearrangement(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5933 题意:长度为nn的数组:a_1, a_2, \cdotsa​1​​,a​2​​,⋯, 每次操作要么可以merge两个相邻的数为一个, 值为两个数的和; 要么可以把一个数分裂成两个, 两个数的和为原数. 用最少的操作把数组变换成长度为KK且所有数值相等的数组, 无解输出-1−1。 读错题了啊...

weixin_30682415的博客 88

HDU-5933 ArcSoft's Office Rearrangement(思维)

ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 156    Accepted Submission(s): 75 Problem Description Ar

huatian5的博客 761
上一篇: 景驰无人驾驶 1024 编程邀请赛 - A. 热爱工作的蒜蒜 (A*)
下一篇: HDU 5934 - Bomb(tarjan缩点+建图)
Mr_Treeeee
博客等级 码龄10年 38粉丝 551原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值