博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 3280 Equal Sum Partitions(二分查找)
阅读量:5900 次
发布时间:2019-06-19

本文共 2417 字,大约阅读时间需要 8 分钟。

Equal Sum Partitions

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 551    Accepted Submission(s): 409
Problem Description
An
equal sum partition of a sequence of numbers is a grouping of the numbers (in the same order as the original sequence) in such a way that each group has the same sum. For example, the sequence:
2 5 1 3 3 7
may be grouped as:
(2 5) (1 3 3) (7)
to yield an equal sum of
7.
Note: The partition that puts all the numbers in a single group is an equal sum partition with the sum equal to the sum of all the numbers in the sequence.
For this problem, you will write a program that takes as input a sequence of positive integers and returns the smallest sum for an equal sum partition of the sequence.
 
Input
The first line of input contains a single integer
P, (1 ≤
P ≤ 1000), which is the number of data sets that follow. The first line of each data set contains the data set number, followed by a space, followed by a decimal integer
M, (1 ≤
M ≤ 10000), giving the total number of integers in the sequence. The remaining line(s) in the dataset consist of the values, 10 per line, separated by a single space. The last line in the dataset may contain less than 10 values.
 
Output
For each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the smallest sum for an equal sum partition of the sequence.
 
Sample Input
 
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
 
Sample Output
 
1 7 2 21 3 2
 
Source
 
Recommend

/* 题意:n个数,分成若干个集合,要求每一个集合的数和同样,求集合最小值 思路:枚举当前集合推断是否满足条件*/#include
#include
#include
#include
#include
using namespace std;typedef __int64 ll;#define N 10005#define INF 0x3f3f3f3fint 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;}

转载地址:http://myesx.baihongyu.com/

你可能感兴趣的文章
objective c:import和include的区别, ""和<>区别
查看>>
spring SchedulerFactoryBean 没有创建 Scheduler的实现类bea
查看>>
基于cobbler实现自动化安装系统
查看>>
The Shared folder with you
查看>>
BodyPaint__操作步骤
查看>>
poj 2234 Matches Game
查看>>
2018年全国多校算法寒假训练营练习比赛(第五场)
查看>>
sax方式解析XML学习笔记
查看>>
Springboot配置(上)
查看>>
Luogu345: [POI2007]POW-The Flood
查看>>
java--Eclipse for mac 代码提示(代码助手,代码联想)快捷键修改
查看>>
Jdom的简单操作
查看>>
left join on/right join on/inner join on/full join on连接
查看>>
Codeforces 582B Once Again
查看>>
template.helper 多参数
查看>>
RadioButton布局图片+文字 实现tabhost效果
查看>>
access中设置不等于
查看>>
hdu 1221 Rectangle and Circle
查看>>
Android 四大组件之四(ContentProvider)
查看>>
Android 四大组件之一(Activity)
查看>>