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

Posted Coolxxx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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): 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 a1a2?aN, indicating the size of current blocks.

Limits
1T100
1N105
1K105
1ai105
 

 

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次,即为答案。

 

技术分享
 1 //
 2 //by coolxxx
 3 //#include<bits/stdc++.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<map>
 9 #include<stack>
10 #include<queue>
11 #include<set>
12 #include<bitset>
13 #include<memory.h>
14 #include<time.h>
15 #include<stdio.h>
16 #include<stdlib.h>
17 #include<string.h>
18 //#include<stdbool.h>
19 #include<math.h>
20 #pragma comment(linker,"/STACK:1024000000,1024000000")
21 #define min(a,b) ((a)<(b)?(a):(b))
22 #define max(a,b) ((a)>(b)?(a):(b))
23 #define abs(a) ((a)>0?(a):(-(a)))
24 #define lowbit(a) (a&(-a))
25 #define sqr(a) ((a)*(a))
26 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
27 #define mem(a,b) memset(a,b,sizeof(a))
28 #define eps (1e-10)
29 #define J 10000
30 #define mod 1000000007
31 #define MAX 0x7f7f7f7f
32 #define PI 3.14159265358979323
33 #define N 100004
34 using namespace std;
35 typedef long long LL;
36 double anss;
37 LL aans;
38 int cas,cass;
39 int n,m,lll,ans;
40 LL sum,summ;
41 LL s[N];
42 int a[N];
43 int main()
44 {
45     #ifndef ONLINE_JUDGEW
46 //    freopen("1.txt","r",stdin);
47 //    freopen("2.txt","w",stdout);
48     #endif
49     int i,j,k;
50     int x,y,z;
51 //    init();
52 //    for(scanf("%d",&cass);cass;cass--)
53     for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
54 //    while(~scanf("%s",s))
55 //    while(~scanf("%d%d",&n,&m))
56     {
57         sum=0;aans=0;
58         printf("Case #%d: ",cass);
59         scanf("%d%d",&n,&m);
60         for(i=1;i<=n;i++)
61         {
62             scanf("%d",&a[i]);
63             s[i]=s[i-1]+a[i];
64             sum+=a[i];
65         }
66         if(sum%m){puts("-1");continue;}
67         summ=sum/m;
68         for(i=1;i<n;i++)
69         {
70             if(s[i]%summ==0)
71                 aans-=2;
72         }
73         aans+=n-1+m-1;
74         printf("%lld\n",aans);
75     }
76     return 0;
77 }
78 /*
79 //
80 
81 //
82 */
View Code

 

 

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 a1a2?aN, indicating the size of current blocks.

Limits
1T100
1N105
1K105
1ai105
 

 

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 模拟(中国大学生程序设计竞赛(杭州))的主要内容,如果未能解决你的问题,请参考以下文章

hdu-5933----hdu-5943

2016 杭州区域赛补题

HDU 5933/思维

HDU 2110-Crisis of HDU(母函数)

HDU2110 Crisis of HDU母函数

HDU2110 Crisis of HDU母函数