2016青岛网络赛 Sort
Sort
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Alice will give Bob N sorted sequences, and the i-th sequence includes ai elements. Bob need to merge all of these sequences. He can write a program, which can merge no more than k
sequences in one time. The cost of a merging operation is the sum of
the length of these sequences. Unfortunately, Alice allows this program
to use no more than T cost. So Bob wants to know the smallest k to make the program complete in time.
For each test case, the first line consists two integers N (2≤N≤100000) and T (∑Ni=1ai<T<231).
In the next line there are N integers a1,a2,a3,...,aN(∀i,0≤ai≤1000).
5 25
1 2 3 4 5
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <algorithm>
- #include <climits>
- #include <cstring>
- #include <string>
- #include <set>
- #include <map>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <list>
- #define rep(i,m,n) for(i=m;i<=n;i++)
- #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
- #define mod 1000000007
- #define inf 0x3f3f3f3f
- #define vi vector<int>
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define se second
- #define ll long long
- #define pi acos(-1.0)
- #define pii pair<int,int>
- #define Lson L, mid, rt<<1
- #define Rson mid+1, R, rt<<1|1
- const int maxn=1e5+;
- using namespace std;
- ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
- ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
- int n,m,k,t,a[maxn];
- bool check(int k)
- {
- int i,j,ans=,now,cnt;
- queue<int>p,q;
- rep(i,,n)p.push(a[i]);
- if((j=(n-)%(k-))!=)
- {
- now=;
- rep(i,,j+)now+=p.front(),p.pop();
- ans+=now,q.push(now);
- }
- while(p.size()+q.size()>)
- {
- cnt=now=;
- while(cnt<k)
- {
- if(!p.empty()&&(q.empty()||p.front()<=q.front()))now+=p.front(),p.pop();
- if(!q.empty()&&(p.empty()||q.front()<=p.front()))now+=q.front(),q.pop();
- cnt++;
- }
- ans+=now,q.push(now);
- }
- return ans<=m;
- }
- int main()
- {
- int i,j;
- scanf("%d",&t);
- while(t--)
- {
- scanf("%d%d",&n,&m);
- rep(i,,n)scanf("%d",&a[i]);
- sort(a+,a+n+);
- int l=,r=n,ans;
- while(l<=r)
- {
- int mid=l+r>>;
- if(check(mid))ans=mid,r=mid-;
- else l=mid+;
- }
- printf("%d\n",ans);
- }
- //system("Pause");
- return ;
- }
2016青岛网络赛 Sort的更多相关文章
- HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)
题目链接 2016 青岛网络赛 Problem C 题意 给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...
- 2016 年青岛网络赛---Sort(k叉哈夫曼)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5884 Problem Description Recently, Bob has just learn ...
- HDU - 5878 2016青岛网络赛 I Count Two Three(打表+二分)
I Count Two Three 31.1% 1000ms 32768K I will show you the most popular board game in the Shanghai ...
- HDU - 5887 2016青岛网络赛 Herbs Gathering(形似01背包的搜索)
Herbs Gathering 10.76% 1000ms 32768K Collecting one's own plants for use as herbal medicines is pe ...
- HDU5887 Herbs Gathering(2016青岛网络赛 搜索 剪枝)
背包问题,由于数据大不容易dp,改为剪枝,先按性价比排序,若剩下的背包空间都以最高性价比选时不会比已找到的最优解更好时则剪枝,即 if(val + (LD)pk[d].val / (LD)pk[d]. ...
- HDU 5886 Tower Defence(2016青岛网络赛 I题,树的直径 + DP)
题目链接 2016 Qingdao Online Problem I 题意 在一棵给定的树上删掉一条边,求剩下两棵树的树的直径中较长那的那个长度的期望,答案乘上$n-1$后输出. 先把原来那棵树的 ...
- HDU5880 Family View(2016青岛网络赛 AC自动机)
题意:将匹配的串用'*'代替 tips: 1 注意内存的使用,据说g++中指针占8字节,c++4字节,所以用g++交会MLE 2 注意这种例子, 12abcdbcabc 故失败指针要一直往下走,否则会 ...
- 2016青岛网络赛 Barricade
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Proble ...
- 2016青岛网络赛 The Best Path
The Best Path Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Pr ...
随机推荐
- 转:jmeter之线程组
虽然有三个添加线程组的选项,名字不一样, 创建之后,其界面是完全一样的.之前的版本只有一个线程组的名字.现在多一个setUp theread Group 与terDown Thread Group 1 ...
- POJ 3548 Restoring the digits
暴力搜索.注意题目说每个字母对应的数字不同,这句话表明最多只有10个字母,所以暴力DFS绝对不会TLE. #include<cstdio> #include<cstring> ...
- VBS操作JS网页元素实例
'=========================================================================='' VBScript Source File - ...
- Chapter 1 First Sight——31
I took notes carefully anyway, always looking down. 不论怎么样我都仔细的记着笔记,一直低着头. I couldn't stop myself fro ...
- Linked List 实例
文件功能:实现了动态建立一个学生信息的链表包括链表的创建.插入.删除.和打印输出学生信息包括姓名和分数 #include<iostream> #include<string> ...
- debia下安装libjpeg
今天在编译时遇到如下问题: configure: error: no usable libjpeg; please install libjpeg devel package or equivalen ...
- LD_LIBRARY_PATH vs LIBRARY_PATH
LIBRARY_PATH is used by gcc before compilation to search for directories containing libraries that n ...
- IoC容器Autofac正篇之类型关联(服务暴露)(八)
类型关联 类型关联就是将类挂载到接口(一个或多个)上去,以方便外部以统一的方式进行调用(看下例). 一.As关联 我们在进行手动关联时,基本都是使用As进行关联的. 1 2 3 4 5 6 7 8 ...
- python--lambda和def函数
1.Python lambda和Python def区别分析 Python支持一种有趣的语法,它允许你快速定义单行的最小函数.这些叫做lambda的函数,是从Lisp借用来的,可以用在任何需要函数的地 ...
- Servlet学习三:不允许直接访问jsp处理方式一过滤器
转自:http://zy19982004.iteye.com/blog/1755189