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
  1. 3
  2. 1 6
  3. 2 5 1 3 3 7
  4. 2 6
  5. 1 2 3 4 5 6
  6. 3 20
  7. 1 1 2 1 1 2 1 1 2 1
  8. 1 2 1 1 2 1 1 2 1 1
 
Sample Output
  1. 1 7
  2. 2 21
  3. 3 2
 
Source
 
Recommend

  1. /*
  2. 题意:n个数,分成若干个集合,要求每一个集合的数和同样,求集合最小值
  3. 思路:枚举当前集合推断是否满足条件
  4.  
  5. */
  6. #include<iostream>
  7. #include<cstdio>
  8. #include<cstring>
  9. #include<algorithm>
  10. #include<cmath>
  11. using namespace std;
  12.  
  13. typedef __int64 ll;
  14.  
  15. #define N 10005
  16. #define INF 0x3f3f3f3f
  17.  
  18. int sum[N];
  19. int n;
  20.  
  21. bool fdd(ll temp)
  22. {
  23. int hh=0;
  24. int pos=0;
  25. while(pos!=n)
  26. {
  27. hh+=temp;
  28. pos=upper_bound(sum+1,sum+n+1,hh)-(sum+1);
  29. if(sum[pos]!=hh)
  30. {
  31. return false;
  32. }
  33. }
  34. return true;
  35. }
  36.  
  37. int main()
  38. {
  39. int i,j,t,ca;
  40. sum[0]=0;
  41. scanf("%d",&t);
  42. while(t--)
  43. {
  44. scanf("%d%d",&ca,&n);
  45. int x;
  46. for(i=1;i<=n;i++)
  47. {
  48. scanf("%d",&x);
  49. sum[i]=sum[i-1]+x;
  50. }
  51.  
  52. for(i=1;i<=n;i++)
  53. if(fdd(sum[i])) break;
  54.  
  55. printf("%d %d\n",ca,sum[i]);
  56. }
  57. return 0;
  58. }

HDU 3280 Equal Sum Partitions(二分查找)的更多相关文章

  1. HDU-3280 Equal Sum Partitions

    http://acm.hdu.edu.cn/showproblem.php?pid=3280 用了简单的枚举. Equal Sum Partitions Time Limit: 2000/1000 M ...

  2. HDU 4614 线段树+二分查找

    Vases and Flowers 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4614 Problem Description Alice is s ...

  3. CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)

    传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...

  4. NOJ——1649Find Sum(二分查找)

    [1649] Find Sum 时间限制: 1000 ms 内存限制: 65535 K 问题描述 This problem is really boring. You are given a numb ...

  5. HDU——1397Goldbach's Conjecture(二分查找+素数打表)

    Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  6. CF 600B Queries about less or equal elements --- 二分查找

    CF 600B 题目大意:给定n,m,数组a(n个数),数组b(m个数),对每一个数组b中的元素,求数组a中小于等于数组该元素的个数. 解题思路:对数组a进行排序,然后对每一个元素b[i],在数组a中 ...

  7. [LeetCode] #167# Two Sum II : 数组/二分查找/双指针

    一. 题目 1. Two Sum II Given an array of integers that is already sorted in ascending order, find two n ...

  8. [LeetCode] #1# Two Sum : 数组/哈希表/二分查找/双指针

    一. 题目 1. Two SumTotal Accepted: 241484 Total Submissions: 1005339 Difficulty: Easy Given an array of ...

  9. hdu 2141:Can you find it?(数据结构,二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

随机推荐

  1. Code::Blocks使用与调试一条龙

    CodeBlocks创建C语言工程版本13.12   选择"create a new project" 选择第四个,点击"go" 4 选择"C&quo ...

  2. 高阶函数与接口混入和java匿名类

    高阶函数与接口混入和java匿名类. 高阶函数中的组件(参量)函数相当于面向对象中的混入(接口)类. public abstract class Bird { private String name; ...

  3. 解决【npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141072930277'】方案

    问题描述执行npm install的时候报错npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141 ...

  4. 16第一章 ASP.Net编程基础知识

    第一章        ASP.Net编程基础知识 第一章        ASP.Net编程基础知识 本章首先介绍用ASP.Net技术编制服务器端动态网页所需的网络和HTML标记语言方面的有关知识.然后 ...

  5. JS 水印图片合成实例页面

    CSS代码: .clip { position: absolute; clip: rect(0 0 0 0); } HTML代码: <input type="file" id ...

  6. cc.Label

    cc.Label 1:cc.Label是显示文字的组件;2:cc.Label属性面板:  String: 文本显示的内容;  Horiznotal: 水平对齐的方式: 左 右 居中;  Vertial ...

  7. [Luogu] P1156 垃圾陷阱

    题目描述 卡门――农夫约翰极其珍视的一条Holsteins奶牛――已经落了到“垃圾井”中.“垃圾井”是农夫们扔垃圾的地方,它的深度为D(2≤D≤100)英尺. 卡门想把垃圾堆起来,等到堆得与井同样高时 ...

  8. Codeforces Beta Round #19D(Points)线段树

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  9. Volume 1. String(uva)

    10361 - Automatic Poetry #include <iostream> #include <string> #include <cstdio> # ...

  10. 去面试Python工程师,这几个基础问题一定要能回答,Python面试题No4

    今天的面试题以基础为主,去面试Python工程师,这几个基础问题不能答错 第1题:列表和元组有什么不同? 列表和元组是Python中最常用的两种数据结构,字典是第三种. 相同点: 都是序列 都可以存储 ...