/*E - 二分Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionEvery year the cows hold an event featurin...">
当前位置:   article > 正文

二分PkU3258

二分PkU3258
  1. <span style="color:#330099;">/*
  2. E - 二分
  3. Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
  4. Submit
  5. Status
  6. Description
  7. 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).
  8. 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.
  9. 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).
  10. 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.
  11. Input
  12. Line 1: Three space-separated integers: L, N, and M
  13. Lines 2..N+1: Each line contains a single integer indicating how far some rock is away from the starting rock. No two rocks share the same position.
  14. Output
  15. Line 1: A single integer that is the maximum of the shortest distance a cow has to jump after removing M rocks
  16. Sample Input
  17. 25 5 2
  18. 2
  19. 14
  20. 11
  21. 21
  22. 17
  23. Sample Output
  24. 4
  25. By Grant Yuan
  26. 2014.7.16
  27. */
  28. #include<iostream>
  29. #include<cstdio>
  30. #include<cstring>
  31. #include<cstdlib>
  32. #include<algorithm>
  33. using namespace std;
  34. int l,n,m;
  35. int low,high,mid;
  36. int a[50002];
  37. bool can(int k)
  38. { int sum=0;
  39. int last=0;
  40. for(int i=1;i<n;i++)
  41. {if(a[i]-a[last]<k)
  42. sum++;
  43. else
  44. last=i;}
  45. if(a[n]-a[last]<k)
  46. return false;
  47. else if(sum>m)
  48. return false;
  49. return true;
  50. }
  51. int main()
  52. {
  53. while(~scanf("%d%d%d",&l,&n,&m)){
  54. for(int i=1;i<=n;i++)
  55. scanf("%d",&a[i]);
  56. a[0]=-1;
  57. a[++n]=l;
  58. sort(a,a+n+1);
  59. low=0,high=a[n];
  60. int ans=0;
  61. while(low<=high){
  62. mid=(low+high)*0.5;
  63. if(can(mid)){
  64. low=mid+1;
  65. ans=mid;}
  66. else
  67. high=mid-1;}
  68. cout<<ans<<endl;}
  69. return 0;
  70. }
  71. </span>

转载于:https://www.cnblogs.com/codeyuan/p/4254514.html

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号