当前位置: 首页 > news >正文

音乐中文网站模板下载做园林景观的网站

音乐中文网站模板下载,做园林景观的网站,企业邮箱登录入口官网网页版,网站的形成题意#xff1a; 起始有两个石头#xff0c;位置是000和nnn,在这中间有n个石头#xff0c;问如何拿走m块石头后#xff0c;使得他们之间的最小间隔的最大值。 题目#xff1a; Every year the cows hold an event featuring a peculiar version of hopscotch that invo…题意 起始有两个石头位置是000和nnn,在这中间有n个石头问如何拿走m块石头后使得他们之间的最小间隔的最大值。 题目 Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully jumping from rock to rock in a river. The excitement takes place on a long, straight river with a rock at the start and another rock at the end, L units away from the start (1 ≤ L ≤ 1,000,000,000). Along the river between the starting and ending rocks, N (0 ≤ N ≤ 50,000) more rocks appear, each at an integral distance Di from the start (0 Di L). To play the game, each cow in turn starts at the starting rock and tries to reach the finish at the ending rock, jumping only from rock to rock. Of course, less agile cows never make it to the final rock, ending up instead in the river. Farmer John is proud of his cows and watches this event each year. But as time goes by, he tires of watching the timid cows of the other farmers limp across the short distances between rocks placed too closely together. He plans to remove several rocks in order to increase the shortest distance a cow will have to jump to reach the end. He knows he cannot remove the starting and ending rocks, but he calculates that he has enough resources to remove up to M rocks (0 ≤ M ≤ N). FJ wants to know exactly how much he can increase the shortest distance before he starts removing the rocks. Help Farmer John determine the greatest possible shortest distance a cow has to jump after removing the optimal set of M rocks. Input Line 1: Three space-separated integers: L, N, and M Lines 2…N1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position. Output Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks Sample Input 25 5 2 2 14 11 21 17 Sample Output 4 Hint Before removing any rocks, the shortest jump was a jump of 2 from 0 (the start) to 2. After removing the rocks at 2 and 14, the shortest required jump is a jump of 4 (from 17 to 21 or from 21 to 25). 分析 由于是求最小间隔的最大值起初我理解成求出最大间隔那么直接连续拿遍历一遍就好那肯定是错的那么如何处理每次拿走石头都有可能改变之间间隔的最小值呢 1.首先考虑到只要拿走石头都会使石头之间的间隔变大那么我们只需要枚举最小的间隔看是否满足拿走k个石头后仍旧是最小间隔。 2.那么如何求的最大的最小间隔呢,我们用二分进行枚举最小间隔即可 3.对石头位置进行排序,为之后的遍历寻找去掉一个石头后计算之间的间隔做准备。 4.dfs(x)xdfs(x)xdfs(x)x是所有石头间的最小间隔即任意两个石头之间的间隔都不能小于xxx,我们可以拿走k块石头那就判断当拿走k块石头后仍是最小间隔即可。当存在拿走大于等于k个石头后仍旧是最小间隔时说明此时最小间隔偏大我们最终需要的是正好拿走k个石头使得该枚举的最小间隔是石头间的最小间隔 AC代码 #includestring.h #includestdio.h #includealgorithm #includeiostream using namespace std; const int M5e410; int n,m,k; int f[M]; bool dfs(int x){///假设x是所有石头间的最大最小间隔则此时需要判断拿走k个石头后是否仍是最小间隔。int num0;for(int i1;im-k;i){///一共m-2-k次循环哪怕不满足while循环prem-kint prenum1;while(premf[pre]-f[num]x){///当存在石头间隔小于最小间隔拿走这个石头,使间隔变大pre;}if(prem){///若假设成立,存在拿走k块石头让石头间隔小于最小间隔return false;}numpre;}return true; } int main(){cinnmk;f[0]0;for(int i1;im;i){cinf[i];}f[m1]n;mm2;sort(f,fm);int r0,ln1;//上界要稍大一些否则mid永远取不到值nwhile(l-r1){int mid(rl)1;if(dfs(mid))//说明此时枚举的间隔较小rmid;else lmid;//是否可能使得所有石头之间的距离不小于d}coutrendl;return 0; }
http://www.yutouwan.com/news/283147/

相关文章:

  • 网站建设与电子商务的教案free wordpress themes
  • 做计算机网站的总结网站服务器租赁需要什么手续
  • 云南网站设计平台网站和网络有什么区别
  • 站长之家源码下载湖南网站营销优化开发
  • 企业建设网站需要注意什么手续怎么做软件程序
  • 头像设计制作网站阿里云官网首页
  • php怎么建立站点物业管理系统和物业管理软件
  • 郑州网站推广公司排名苏州电商系统开发
  • 邢台wap网站建设报价重庆建设岗位培训网站
  • 基金会网站建设登录wordpress数据库
  • 做竞品分析去哪个网站互联网有多少网站
  • 怎做连接网站重庆知名设计公司有哪些
  • 大网站开发语言石家庄网站建设公司哪家好
  • 做宠物网站心得网站开发入股合作分配比例
  • php网站开发文本格式设置在网站设计公司上班好吗
  • 网站开发保密合同wordpress 中文文件名
  • 西安网站建设报价方案中国计算机网络公司排名
  • 网站关键字选择标准网站建设风险怎样规避
  • 微商网站模板上海公司排名前十
  • 长沙网建站中国建设银行网站对公账户首页
  • 东莞中赢网站建设公司怎么样建设门户网站需要多少钱
  • 5000多一年的网站建站怎么做物流网站代理
  • dw做网站实例旅游网站的建设开题报告
  • 阜平网站建设电商网站建设意义
  • 茌平做网站推广做网站要买服务器吗
  • 了解网站建设的流程30岁学编程太晚了
  • 如何建设网站哪个济南兴田德润简介免费域名证书申请
  • 做网站前端用什么语言全景网站模版
  • 个人业务网站教程wordpress小图标大全
  • 网站关键词突然没有排名了ppt设计主题