NYOJ 586 疯牛

2014-11-24 12:48:11 · 作者: · 浏览: 1

疯牛

时间限制:1000 ms | 内存限制:65535 KB 难度:4
描述
农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小隔间依次编号为x1,...,xN (0 <= xi <= 1,000,000,000).
但是,John的C (2 <= C <= N)头牛们并不喜欢这种布局,而且几头牛放在一个隔间里,他们就要发生争斗。为了不让牛互相伤害。John决定自己给牛分配隔间,使任意两头牛之间的最小距离尽可能的大,那么,这个最大的最小距离是什么呢?
输入
有多组测试数据,以EOF结束。
第一行:空格分隔的两个整数N和C
第二行――第N+1行:分别指出了xi的位置
输出
每组测试数据输出一个整数,满足题意的最大的最小值,注意换行。
样例输入
5 3
1
2
8
4
9
样例输出
3
二分+贪心!
AC码:
#include
       
        
#include
        
          #include
         
           using namespace std; int num[100005],n,c; int judge(int x) { int cnt=1,temp=num[0],i; for(i=1;i
          
           =x) { cnt++; // 牛的头数加1 temp=num[i]; if(cnt>=c) // 如果在平均最短长度为x时,c头都能放的下 return 1; } } return 0; } int get_ans() { int l=0,r=num[n-1]-num[0],mid; while(l<=r) { mid=(l+r)/2; if(judge(mid)) l=mid+1; else r=mid-1; } return l-1; } int main() { int i; while(~scanf("%d%d",&n,&c)) { for(i=0;i
           
            

<script type="text/java script">
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
分享到: 更多
<script type="text/java script" id="bdshare_js" data="type=tools&uid=12732"> <script type="text/java script" id="bdshell_js"> <script type="text/java script"> var bds_config = {'snsKey':{'tsina':'2386826374','tqq':'5e544a8fdea646c5a5f3967871346eb8'}}; document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js cdnversion=" + Math.ceil(new Date()/3600000)
您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力
上一篇: 1到N的平方和公式
下一篇: 最后一页
相关文章
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
图文推荐
<iframe src="http://www.2cto.com/uapi.php tid=300019&catid=339&title=TllPSiA1ODYgt jFow==&forward=http://www.2cto.com/kf/201405/300019.html" width="100%" height="100%" id="comment_iframe" name="comment_iframe" frameborder="0" scrolling="no">
<script type="text/java script">BAIDU_CLB_fillSlot("771057");