Beautiful Dream

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 629    Accepted Submission(s): 224

Problem Description
When we were a child, we all had a beautiful dream, time flies, where is your colorful dream living in now?
Get it? If not, it doesn’t matter, today is your lucky day, our kindly angel cast some items, if you get more than m different kind of items, you will get the gift of the angel: help you achieve your childhood dream.
Now we know the number of each item, find the maximum number of people who can achieve their dreams.
 
Input
There are several test cases in the input.
The first line of each case contains two integer n (0 < n <= 100) and m (0 < m <= n), indicating the items’ kind number and the least different kind number of items you need collect to achieve your dream.
The n integer follows, indicating number of each item, you can assume the range of items’ number is in 1 - 1 000 000 000.
The input terminates by end of file marker.
 
Output
For each test case, output the maximum number of people who can achieve their dreams.
 
Sample Input
2 2
3 5
3 2
2 2 2
 
Sample Output
3
3
 
直接:
 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int a[];
int main()
{
int m,n,i;long long ans;
while(~scanf("%d%d",&n,&m))
{
ans=;
for(i=;i<n;i++)scanf("%d",&a[i]),ans+=a[i];
bool flag=;
ans/=m;
while(flag)
{
flag=;
for(i=;i<n;i++)
if(a[i]>ans)a[i]=ans,flag=;
ans=;
for(i=;i<n;i++)ans+=a[i];
ans/=m;
}
printf("%I64d\n",ans);
}
}

二分:

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
long long a[];
int main()
{
int m,n,i;long long ans;
while(~scanf("%d%d",&n,&m))
{
ans=;
for(i=;i<n;i++)scanf("%I64d",&a[i]),ans+=a[i];
long long l=,r=ans/m,mid;
while(l<=r)
{
mid=(l+r)>>;
ans=;
for(i=;i<n;i++)ans+=min(a[i],mid);
if(ans>=mid*m)l=mid+;
else r=mid-;
}
printf("%I64d\n",r);
}
}

Beautiful Dream hdu3418 (直接做或二分)的更多相关文章

  1. 转:Beautiful Soup

    Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你节省数小时 ...

  2. [POJ2002]Squares(计算几何,二分)

    题目链接:http://poj.org/problem?id=2002 给定一堆点,求这些点里哪些点可以构成正方形,题目给定n<=1000,直接枚举四个点是肯定会超时的,因此要做一些优化. 有公 ...

  3. UVALive 2238 Fixed Partition Memory Management(二分完美匹配)

    题意:计算机中有一些固定大小的内存,内存越大,处理速度越快.对于一个程序,加入不同的内存空间,处理所需时间不同.现给出m个内存空间,n个程序,对于每个程序程序,有k组数据(s,t),分别表示当程序 i ...

  4. 【二分答案】 【POJ3497】 【Northwestern Europe 2007】 Assemble 组装电脑

    Assemble Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3171   Accepted: 1013 Descript ...

  5. 一些简单二分题,简单的hash,H(i),字符串题

    说在前面: 题是乱七八糟的. 几个二分的题. (但是我的做法不一定是二分,有些裸暴力. 1. Equations HDU - 1496 输入a,b,c,d问你这个方程有多少解.a*x1^2+b*x2^ ...

  6. 2527: [Poi2011]Meteors[整体二分]

    2527: [Poi2011]Meteors Time Limit: 60 Sec  Memory Limit: 128 MB Submit: 1528  Solved: 556 [Submit][S ...

  7. STL模板整理 Binary search(二分查找)

    前言: 之前做题二分都是手动二分造轮子,用起来总是差强人意,后来看到STL才发现前辈们早就把轮子造好了,不得不说比自己手动实现好多了. 常用操作 1.头文件 #include <algorith ...

  8. [Bzoj2282]消防(二分答案+树的直径)

    Description 某个国家有n个城市,这n个城市中任意两个都连通且有唯一一条路径,每条连通两个城市的道路的长度为zi(zi<=1000). 这个国家的人对火焰有超越宇宙的热情,所以这个国家 ...

  9. 牛客NOIP提高组R1 A中位数(二分)

    题意 题目链接 Sol 很神仙的题目啊,考场上只会$n^2$的暴力.. 考虑直接二分一个$mid$,我们来判断最终答案是否可能大于$x$. 判断的时候记录一下前缀最小值即可, 设$s[i]$表示$1- ...

随机推荐

  1. tomcat设置文件编码

    tomcat修改bin文件夹下面的catalina.bat文件可以解决乱码在文件中加上JAVA_OPTS="-server -Xms128M -Xmx4096M -XX:PermSize=5 ...

  2. django框架(View)

    -------------------URLconf-------------------1.设置 1.在settings.py文件中通过ROOT_URLCONF指定根级url的配置 2.urlpat ...

  3. 第1阶段——u-boot分析之make指令(2)

    通过make 100ask24x0_config 指令配置好芯片选型后,使用make指令来生成uboot.bin文件 本文学习目标: 对Makefile文件进行基本了解,掌握make指令是怎么实现生成 ...

  4. 【★】微信之于QQ的市场哲学

    2016年的移动app下载排行榜出炉后,我们惊奇发现,前十名中有6个应用软件来自腾讯公司.而前两名毋庸置疑是远远碾压第三名的微信与qq.这让我们看到社交app的重要性的同时也回到了那个原始的问题:腾讯 ...

  5. CCIE-MPLS VPN-实验手册(下卷)

    10:跨域的MPLS VPN (Option A) 10.1 实验拓扑 10.1 实验需求 a.       R1 R2 R3 组成P-NETWORK R1 R2 R3 位于AS 1,底层协议采用EI ...

  6. a链接易混淆与form表单简易验证用法详解

    链接可以说遍布互联网,比如你想提供一个可以跳转到百度首页的链接给网友,那么代码如下: <a href="http://www.baidu.com">百度一下,你就知道& ...

  7. unity调用c++ dll方法介绍

    摘要 unity用的很普遍,现在很多代码还是用c++写的,需要用unity去调用c++的代码.这里介绍了一种unity调用c++ dll的方法,希望有所帮助. 我采用的软件是Visual Studio ...

  8. 【Beta】阶段 第五次Daily Scrum Meeting

    每日任务 1.本次会议为第五次 Meeting会议: 2.本次会议在周五下午15:35,在禹洲楼召开,召开本次会议为10分钟. 一.今日站立式会议照片 二.每个人的工作 (有work item 的ID ...

  9. 201521123078《Java程序设计》第七周学习总结

    1. 本周学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 public boolean contains(Object o) { re ...

  10. 201521123019 《Java程序设计》第7周学习总结

    1. 本章学习总结 2. 书面作业 Q1.ArrayList代码分析 1.1解释ArrayList的contains源代码 源代码如下: public boolean contains(Object ...