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
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
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

2016年中国大学生程序设计竞赛(杭州)




智障啊。。。。

真心智障啊。。。。。。

我怎么这么智障啊。。。。。

感觉人生就和这个智障的题目一样。。。。最后就智障地错过重要的东西。。。。孤独终老。。。死前躺在床上一脸不甘愿,然后嗝屁了吧。。。


干。。。。


这题吗。。。一开始想了很久啊。。。然后听了张嘉涛的想法感觉很有意思就写写写,然后就不会写了。。。。

然后周围的人好像都很顺利的样子。。。。

然后就开始吃红薯。。。。

zyyyyy昨晚发烧了,看上去很虚弱,向我要了一个红薯,没想到他居然烧到四十度!!!!

太强了,烧了四十度还过了四道题。。。。

不过这是后话了。。。

总之这题不难啊。。。。怎么一直在做智力题呢。。。


可以把题目的输入相成一个x轴的坐标嘛

输入:

|      |                      |               |     |              |               |              |

——-——————————————————————

0    1                     4              6    7            9              11            13


目标:

|      |      |       |      |       |       |      |      |        |      |       |       |        |

—————————————————————————

1    2    3       4     5     6       7     8    9      10   11   12   13  

要变成均匀的段子嘛。。。。

最坏的情况就是我们先把所有的格子先合并起来,然后再均匀拆分呗

那么什么情况不用合并拆分呢,就是输入的那条轴上的点能在目标轴上找到呗。。。

这样就不用合并拆分。。。

自己就是个傻逼。。。

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <sstream>
#include <queue>
using namespace std;
const int maxn = 1e5+10;
long long result,killme;
long long a[maxn];

bool search2(long long x,long long *p,long long len){
    long long left=0,right=len-1;
    while(left<=right)
    {
        long long mid=(left+right)/2;
        if(x>p[mid])
            left=mid+1;
        else if(x==p[mid])
        {
            return true;
        }
        else
            right=mid-1;
    }
    return false;
}
long long final[maxn];
long long save[maxn];
int main(){
    int t;
    scanf("%d",&t);
    int rnd = 1;
    while(t--){
        long long n,k,i,j;
        scanf("%lld%lld",&n,&k);
        long long ans = 0;
        for(i=1;i<=n;i++){
            scanf("%lld",&a[i]);
            ans += a[i];
        }
        for(i=1;i<=n;i++){
            if(i==1){
                save[1]=a[1];
            }else{
                save[i]=save[i-1]+a[i];
            }
        }
        
        
        if(ans%k){
            printf("Case #%d: -1\n",rnd);
            rnd++;
            continue;
        }
        long long aver=ans/k;
        for(i=1;i<=k;i++){
            final[i] =aver*i;
        }
        result = n-1+k-1;
        for(i=1;i<k;i++){
            if(search2(final[i], save+1, n)){
                result-=2;
            }
        }
        
        printf("Case #%d: %lld\n", rnd, result);
        rnd++;
        
    }
    return 0;
}
关于zyyyyy的故事,在1006的题解里继续

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值