P1094 纪念品分组
来源:互联网 发布:php判断是否点击submit 编辑:程序博客网 时间:2024/05/22 15:54
题目描述
有n个礼物,给出每个礼物的价格,按价格分组,每组最多两个礼物,每组礼物价格不能超过M,求最小分多少组。
样例输入
100 9 90 20 20 30 50 60 70 80 90
样例输出
6
思路
排序,从小到大,看看小的和大的最多组成的个数。
var n:longint; a:array[1..30000] of longint;procedure qsort(l,r:longint);var i,j,key,temp:longint;begin if l>=r then exit; i:=l;j:=r; key:=a[l+random(r-l+1)]; repeat while (a[i]<key) do inc(i); while (a[j]>key) do dec(j); if i<=j then begin temp:=a[i];a[i]:=a[j];a[j]:=temp; inc(i);dec(j); end; until i>j; qsort(l,j); qsort(i,r);end;var i,j,m,p:longint;begin readln(m); readln(n); for i:=1 to n do readln(a[i]); randomize; qsort(1,n); j:=n;i:=1; while i<=j do if a[i]+a[j]<=m then begin inc(i);inc(p);dec(j);end else if a[j]<=m then begin dec(j);inc(p);end else dec(j); writeln(p);end.
0 0
- P1094 纪念品分组
- P1094 纪念品分组
- 洛谷 P1094 纪念品分组
- 洛谷 P1094 纪念品分组
- 洛谷P1094 纪念品分组
- P1094 纪念品分组
- 洛谷 P1094 纪念品分组
- P1094 纪念品分组
- 【贪心】洛谷 P1094 纪念品分组
- 纪念品分组
- 纪念品分组
- 纪念品分组
- 纪念品分组
- 纪念品分组
- 纪念品分组
- 纪念品分组
- 纪念品分组
- 纪念品分组
- 简易rest接口调试工具
- Expandablelistview 简单使用
- 使用idea+springboot+Mybatis搭建web项目
- WebP 探寻之路
- Java并发编程:如何创建线程?
- P1094 纪念品分组
- 类的静态成员
- protobuf引入不同包下的proto文件
- oj中用到的一些数学上的算法
- xposed源码编译与集成
- JavaScript之window.console
- c regex 用法
- jsp9大内置对象详解
- xcode创建一个游戏项目