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

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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  5943 5942 5941 5940 5939 
 

Statistic | Submit | Discuss | Note

题目链接:

  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

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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  5943 5942 5941 5940 5939 
 

Statistic | Submit | Discuss | Note

HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))的更多相关文章

  1. HDU 5968 异或密码 【模拟】 2016年中国大学生程序设计竞赛(合肥)

    异或密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Des ...

  2. HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))

    扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...

  3. HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))

    Car Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  4. 2016年中国大学生程序设计竞赛(合肥)-重现赛1009 HDU 5969

    最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  5. HDU 5963 朋友 【博弈论】 (2016年中国大学生程序设计竞赛(合肥))

    朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Descr ...

  6. HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))

    最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem De ...

  7. HDU 5961 传递 【图论+拓扑】 (2016年中国大学生程序设计竞赛(合肥))

    传递 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)     Problem ...

  8. HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. HDU 5936 Difference 【中途相遇法】(2016年中国大学生程序设计竞赛(杭州))

    Difference Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

随机推荐

  1. 解读zookeeper的配置项

    zookeeper的默认配置文件为zookeeper/conf/zoo_sample.cfg,需要将其修改为zoo.cfg.其中各配置项的含义,解释如下: 1.tickTime:CS通信心跳数 Zoo ...

  2. [时间操作] C#TimeHelper时间格式化帮助类 (转载)

    点击下载 TimeHelper.rar 主要功能如下 .将时间格式化成 年月日 的形式,如果时间为null,返回当前系统时间 .将时间格式化成 时分秒 的形式,如果时间为null,返回当前系统时间 . ...

  3. C#DbHelperMySQL数据库帮助类 (转载)

    主要功能如下数据访问抽象基础类 主要是访问Mysql数据库主要实现如下功能 .得到最大值 .是否存在 .是否存在(基于MySqlParameter) .执行SQL语句,返回影响的记录数 .执行MySq ...

  4. Android 网络视频播放器

    项目概要: 1.登录界面 2.播放列表 3.播放界面

  5. hadoop_并行写操作思路_2

    如果想实现将 Client端的 File并行写入到 各个Datanode中, 首先, 应该修改的是,DistributedFileSystem中的create方法, 在create 内部调用FSNam ...

  6. Using native GDI for text rendering in C#

    Using native GDI for text rendering in C# Aug12by Arthur To complete my previous post on text render ...

  7. double 类型运算会出现精度问题

    要先转换为字符串,后进行运算,可以写个方法做乘法运算public static double mul(double v1,double v2){BigDecimal b1 = new BigDecim ...

  8. [Neural Networks] Momentum

    一.目的 加快参数的收敛速度. 二.做法 另第t次的权重更新对第t+1次的权重更新造成影响. 从上式可看出,加入momentum后能够保持权重的更新方向,同时加快收敛.通常alpha的取值为[0.7, ...

  9. js 之 json

    /*JSON语法数据在名称/值对中数据由逗号分隔花括号保存对象方括号保存数组 JSON 数据的书写格式是:名称/值对名称/值对包括字段名称(在双引号中),后面写一个冒号,然后是值;如"myw ...

  10. jquery 左侧展开栏目

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...