Minimum Sum(思维)
There are n numbers A[1] , A[2] .... A[n], you can select m numbers of it A[B[1]] , A[B[2]] ... A[B[m]] ( 1 <= B[1] < B[2] .... B[m] <= n ) such that Sum as small as possible.
Sum is sum of abs( A[B[i]]-A[B[j]] ) when 1 <= i < j <= m.

- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<algorithm>
- using namespace std;
- const int MAXN = ;
- int A[MAXN];
- int main(){
- int n,m;
- while(~scanf("%d%d",&n,&m)){
- for(int i = ; i < n; i++){
- scanf("%d",&A[i]);
- }
- sort(A, A + n);
- int ans = 0x3f3f3f3f;
- for(int i = n - m; i >= ;i--){
- int x = m - , temp = ;
- for(int j = i + m - ; j >= i;j--){
- temp += x * A[j];
- // printf("x = %d a[%d] = %d temp = %d ",x,j,A[j],temp);
- x -= ;
- }
- // printf("i = %d\n",i);
- ans = min(ans, temp);
- }
- printf("%d\n",ans);
- }
- return ;
- }
Minimum Sum(思维)的更多相关文章
- 数学 - Whu 1603 - Minimum Sum
Minimum Sum Problem's Link ------------------------------------------------------------------------- ...
- geeksforgeeks@ Minimum sum partition (Dynamic Programming)
http://www.practice.geeksforgeeks.org/problem-page.php?pid=166 Minimum sum partition Given an array, ...
- Minimum Sum LCM(uva10791+和最小的LCM+推理)
L - Minimum Sum LCM Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- UVA.10791 Minimum Sum LCM (唯一分解定理)
UVA.10791 Minimum Sum LCM (唯一分解定理) 题意分析 也是利用唯一分解定理,但是要注意,分解的时候要循环(sqrt(num+1))次,并要对最后的num结果进行判断. 代码总 ...
- Minimum Sum of Array(map迭代器)
You are given an array a consisting of n integers a1, ..., an. In one operation, you can choose 2 el ...
- HDU 3473 Minimum Sum(划分树)
Minimum Sum Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Minimum Sum of Array(map)
You are given an array a consisting of n integers a1, ..., an. In one operation, you can choose 2 el ...
- Whu 1603——Minimum Sum——————【单个元素贡献、滑窗】
Problem 1603 - Minimum Sum Time Limit: 2000MS Memory Limit: 65536KB Total Submit: 623 Accepted: ...
- HDOJ 3473 Minimum Sum
划分树,统计每层移到左边的数的和. Minimum Sum Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- 剑指offer-面试题13.在O(1)时间删除链表节点
题目:给定单向链表的头指针和一个节点指针,定义一个函数在O(1)时间删除该节点. 链表节点与函数的定义如下. 通常我们删除某个节点都是从头开始遍历到需要删除节点的前一个节点. 然后使得该节点的next ...
- 360极速浏览器 HTML5实验室
360极速浏览器 HTML5实验室 HTML5 实验室
- 【转】__attribute__机制介绍
1. __attribute__ GNU C的一大特色(却不被初学者所知)就是__attribute__机制. __attribute__可以设置函数属性(Function Attribute).变量 ...
- hdu 5626 Clarke and points
Problem Description Clarke is a patient with multiple personality disorder. One day he turned into a ...
- Unity 关于属性的get/set
学习Unity的可能多数是C#转过来的, 一进来的时候你会发现Unity编写代码,在一些视频或文章中.基本都没有用过get/set使用, 多数是public string name;这样写的公开字段, ...
- 带你走近AngularJS - 创建自己定义指令
带你走近AngularJS系列: 带你走近AngularJS - 基本功能介绍 带你走近AngularJS - 体验指令实例 带你走近AngularJS - 创建自己定义指令 ------------ ...
- C 语言中实现数据与方法的封装
在 C 语言中可以用结构体代替类,用函数指针代替成员方法,实现数据成员与成员方法的封装,在客户端写出的程序与 C++ 类似,唯一的不同是 C 语言中调用函数指针成员时必须将本对象的地址传给函数,因为 ...
- MySQL5.6 windows7下安装及基本操作
图形界面安装MySQL5.6关于图形界面的安装,网上相关相关资料比较多,此处省略安装过程.安装过程中选择安装路径.所需组件及root账号密码.1.目前针对不同用户,MySQL提供了2个不同的版本:My ...
- .NET中的CSV导入导出(实例)
导入代码,从csv文件得到datatable /// <summary> /// Get Data From Csv File /// (Th ...
- 使用bootstrap时遇到的问题及解决办法
1.用到 Glyphicons图标组件时,要注意文件的存放位置,最好在站点下将下好的bootstrap文件夹复制过来,里面的fonts文件夹不要动,使用的时候直接引用bootstrap.css和boo ...