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
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.
3 1 3 14 3 1 2 3 4 3 6 1 2 3
Case #1: -1 Case #2: 2 Case #3: 3
智障啊。。。。
真心智障啊。。。。。。
我怎么这么智障啊。。。。。
感觉人生就和这个智障的题目一样。。。。最后就智障地错过重要的东西。。。。孤独终老。。。死前躺在床上一脸不甘愿,然后嗝屁了吧。。。
干。。。。
这题吗。。。一开始想了很久啊。。。然后听了张嘉涛的想法感觉很有意思就写写写,然后就不会写了。。。。
然后周围的人好像都很顺利的样子。。。。
然后就开始吃红薯。。。。
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的题解里继续