HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))
ArcSoft's Office Rearrangement
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3 Accepted Submission(s): 2Problem DescriptionArcSoft, 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.
InputFirst 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≤105OutputFor 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 Input3
1 3
14
3 1
2 3 4
3 6
1 2 3Sample OutputCase #1: -1
Case #2: 2
Case #3: 3SourceRecommend
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5933
题目大意:
原先有N个有顺序的车间,大小分别位Ai,现在要把这N个车间重新划分成M个(只能和相邻的合并,分解),要求每个区间大小相等,问是否有解。
(合并区间与拆分区间)
题目思路:
【模拟】
无解的情况是N个区间的总大小s mod M ! = 0
其实题目就是给你一个总长位s的N个区间,要求你合并相邻的两个或拆开一个大区间,使得最后的每个区间大小都为s/M。
那么如果原先的分界线和最终的分界线相同,那么就不必对这个分界线进行合并。
有解的时候可以知道每个新区间的大小x,所以只要看Ai的前缀和里是否有x的倍数,如果有则这个位置不用操作。
总共需要合并N-1次,拆分M-1次,扣掉不需要的操作t*2次,即为答案。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#define N 100004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
LL sum,summ;
LL s[N];
int a[N];
int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d%d",&n,&m))
{
sum=;aans=;
printf("Case #%d: ",cass);
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
s[i]=s[i-]+a[i];
sum+=a[i];
}
if(sum%m){puts("-1");continue;}
summ=sum/m;
for(i=;i<n;i++)
{
if(s[i]%summ==)
aans-=;
}
aans+=n-+m-;
printf("%lld\n",aans);
}
return ;
}
/*
// //
*/
ArcSoft's Office Rearrangement
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3 Accepted Submission(s): 2
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.
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
If the CEO can't re-arrange K new blocks with equal size, y equals -1.
1 3
14
3 1
2 3 4
3 6
1 2 3
Case #2: 2
Case #3: 3
Statistic | Submit | Discuss | Note
HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))的更多相关文章
- HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)
异或密码 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Des ...
- HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))
扫雷 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...
- HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))
Car Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 2016年中国大学生程序设计竞赛(合肥)-重现赛1009 HDU 5969
最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))
朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...
- HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))
最大的位或 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem De ...
- HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))
传递 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem ...
- HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))
Equation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))
Difference Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- fseek()
原文地址:fseek()作者:xiaoxin 意思是把文件指针指向文件的开头 fseek 函数名: fseek 功 能: 重定位流上的文件指针 用 法: int fseek(FILE *s ...
- node express
在某QQ群里,发现大家都在搞node,为了不被out,这周主要研究了一下,还挺高大上. 参考了下资料,适合初学者学习. Node和NPM的安装够便捷了,不细说...有几点基础顺手提一下: 安装命令中的 ...
- 日志记录组件[Log4net]详细介绍
转载:http://www.cnblogs.com/liwei6797/archive/2007/04/27/729679.html 因为工作中有要用到Log记录,找到一篇不错的文章,就转了过来. 一 ...
- windows下安装wamp和wordpress
安装wamp WAMP是一个windows上的php开发集成环境,一键安装php,apache和mysql,非常方便. 双击wampserver2.2exxxxxxxxxx.exe文件进行安装,安装过 ...
- jQuery HTML CSS 方法
jQuery HTML / CSS 方法 下面的表格列出了所有用于处理 HTML 和 CSS 的 jQuery 方法. 下面的方法适用于 HTML 和 XML 文档.除了:html() 方法. 方法 ...
- libConfuse的使用
前言 在软件编程中经常会使用到一些参数,在存储方面一般有使用XML的,也有使用文本文件的,或者使用数据库的等.我们软件平台一些参数是使用XML文件存储,在读取方面的速度还可以,但在写回文件速度一般.也 ...
- 制作Net程序的帮助文档--总结
一.工具的准备 目前,一般采用Sandcastle Help File Builder工具来制作.Net程序帮助文档,该工具主要是利用Xml文档里的信息以及DLL文件来生成完整的帮助文档.在Visua ...
- 【elasticsearch】(2)centos7 超简单安装elasticsearch 的监控、测试的集群工具elasticsearch head
elasticsearch-head是elasticsearch(下面称ES)比较普遍使用的可监控.测试等功能的集群管理工具,是由H5编写的单独的网页程序.使用方法网上很多,这里教大家一个超简单安装h ...
- (转)ASP.NET-关于Container dataitem 与 eval方法介绍
Container是一个数据容器,代表集合类或者dataview中的一行,而Container.dataitem代表该行的数据:所有的container 被存 放在是一个栈堆stack中,自动的将 ...
- 黑马程序员——vim编辑器的使用
------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- 一.基本操作 1.从命令提示符进入vim编辑器: vim filename <ENTE ...