励志用更少的代码做更高效的表达


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≤10^5
1≤K≤10^5
1≤ai≤10^5

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


模拟题, 别想的太复杂。 分解+组合为一组、两次操作。


代码展示

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;int a[100010];
int main() {int T; scanf("%d", &T);for(int t = 1; t <= T; t++) {ll n, k, sum=0, sum1=0, x=0;scanf("%lld%lld", &n, &k);for(int i = 0; i < n; i++) {scanf("%d", &a[i]);sum+=a[i];}if(sum%k) {printf("Case #%d: -1\n",t);} else {k = sum/k;for(int i = 0; i < n; i++) {x += a[i];while(x > k) {x -= k;sum1++;}if(x == k) x = 0;else sum1++;}printf("Case #%d: %lld\n", t,sum1);}}
return 0; }

日拱一卒,功不唐捐。

30行代码AC_HDU-5933 ArcSoft‘s Office Rearrangement(模拟+题解报告)相关推荐

  1. 30行代码,带你分分钟创建神经网络!(附工具教程)

    来源:大数据文摘 作者:Per Haiald Borgen 本文长度为1612字,建议阅读3分钟 本文为你介绍如何使用Synaptic.js创建和训练神经网络. 本文含大量代码,如需原文请从文末来源链 ...

  2. vb.net读取excel并写入dgv_读取PDF中的表格写入EXCEL?30行代码搞定

    办公自动化系列+1 现在,各类数据分析的书籍,都可以在网上找到PDF版本: 同时,百度文库.各类数据统计文库.行业研究等众多论文报告,是通过PDF的形式去展示输出的: 但是,令人都头疼的是,各类数据分 ...

  3. thymealf如何实现传单个变量给html_梦回2013,看尤大vue的第一行代码,如何用30行代码实现vue(超简洁,适合初学者)...

    非非非标题党,干货预警!!! 介绍 大家好,我是清池交友 app 开发日记,记录清池交友 app 开发中学习过程和踩坑日记,伪全栈[1] 技术栈:前端 js,vue,uniapp,后端 java 尤大 ...

  4. Python程序员30行代码素描表白!网友:花里胡哨

    总有人说程序员不够浪漫!其实我们只是没时间而已,等我们有时间了,还有普通人什么事儿?最近就有一个小伙伴上热搜了! 原来他用Python给可爱的女朋友画了一幅素描!不到30行代码,一起来学学给她一个惊喜 ...

  5. 30 行代码实现蚂蚁森林自动“偷”能量

    作者 | xindoo 来源 | CSDN 博客,已获作者授权 虽然我支付宝加了好多好友,平时有很多能量可以"偷",但由于太懒,至今一棵树都没种成,所以心心念念把偷能量这事自动化. ...

  6. python你TM太皮了——区区30行代码就能记录键盘的一举一动

    先看看效果 Like This↓ 一.公共WiFi 公用电脑什么的 在我们日常在线上工作.玩耍时,不论开电脑.登录淘宝.玩网游 统统都会用到键盘输入 在几乎所有网站,例如淘宝.百度.126邮箱等等 为 ...

  7. 太厉害了!30行代码抓取上万个小姐姐跳舞视频,有点飘了~

    点上方"菜鸟学Python",选择"星标" 第481篇原创干货,第一时间送达 大家好,我是菜鸟哥!这个我第481篇原创! 今天又给大家带来一个有趣的Python ...

  8. 一个包含30行代码的Python项目:如何在您最喜欢的Twitcher流式传输时设置SMS通知...

    Hi everyone :) Today I am beginning a new series of posts specifically aimed at Python beginners. Th ...

  9. 代码补全快餐教程(1) - 30行代码见证奇迹

    代码补全快餐教程(1) - 30行代码见证奇迹 下面是我用30多行代码,包含了很多空行和注释的代码写成的代码补全模型.我们先看看效果吧. 补全效果案例 先来看个比较普通的(Python, Keras) ...

  10. 30 行代码实现蚂蚁森林自动收能量(附送源码)

    点击上方 IT牧场 ,选择 置顶或者星标技术干货每日送达! blog.csdn.net/article/details/113734855 推荐:https://www.xttblog.com/?p= ...

最新文章

  1. python yield yield from
  2. 主题模型简介(Topic Models)
  3. 用Python机器学习搞定验证码
  4. Linux Qt使用POSIX多线程条件变量、互斥锁(量)
  5. python画函数图像要用到的模块_教你如何绘制数学函数图像——numpy和matplotlib的简单应用...
  6. 使用 Benchmark.NET 测试代码性能
  7. Flex读取XML不刷新问题
  8. 【文献学习】强化学习1:基于值函数的方法
  9. [转载] Python递归遍历目录下所有文件查找指定文件
  10. action与jsp传值的几种方法
  11. Ubuntu 下实现类似Everything的功能
  12. 使用 PyQT5 来做一个简易版库存管理系统(二)
  13. Convert excel format exception.You can try specifying the ‘excelType‘ yourse-----EasyExcel导入
  14. html 怎么让他变成圆角,html让图片变圆角
  15. 移动宽带服务器维护,移动宽带 设置服务器
  16. 启发式算法(heuristic)
  17. PostgreSQL 15.0下载与安装详细保姆教程
  18. 图像空间域分析之图像统计特征
  19. ABAP ONF4 事件 查找表
  20. 【练习】星巴克介绍页面

热门文章

  1. 从流量控制算法谈网络优化-TCP核心原理理解
  2. kafka数据可靠性深度解读
  3. 面试官:String的最大长度是多少?
  4. shell编程之case语句及函数
  5. RGB、YUV像素基础知识及处理数据
  6. 保护1000万篇原创文章,区块链技术如何做到
  7. Kubernetes Ingress 控制器的技术选型技巧
  8. Spark源码和调优简介 Spark Core
  9. 科普篇 | 推荐系统之矩阵分解模型
  10. ffmpeg源码学习之time_base