标签:regional size get puts group ping inpu bsp numbers
3 1 6 2 5 1 3 3 7 2 6 1 2 3 4 5 6 3 20 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1
1 7 2 21 3 2
/*
题意:n个数,分成若干个集合,要求每一个集合的数和同样,求集合最小值
思路:枚举当前集合推断是否满足条件
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef __int64 ll;
#define N 10005
#define INF 0x3f3f3f3f
int sum[N];
int n;
bool fdd(ll temp)
{
int hh=0;
int pos=0;
while(pos!=n)
{
hh+=temp;
pos=upper_bound(sum+1,sum+n+1,hh)-(sum+1);
if(sum[pos]!=hh)
{
return false;
}
}
return true;
}
int main()
{
int i,j,t,ca;
sum[0]=0;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&ca,&n);
int x;
for(i=1;i<=n;i++)
{
scanf("%d",&x);
sum[i]=sum[i-1]+x;
}
for(i=1;i<=n;i++)
if(fdd(sum[i])) break;
printf("%d %d\n",ca,sum[i]);
}
return 0;
}
HDU 3280 Equal Sum Partitions(二分查找)
标签:regional size get puts group ping inpu bsp numbers
原文地址:http://www.cnblogs.com/clnchanpin/p/6882860.html