zoukankan      html  css  js  c++  java
  • H

    The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The width of the river is L (1<= L <= 1000000000). There are n (0<= n <= 500000) stones lined up in a straight line from one side to the other side of the river. The frogs can only jump through the river, but they can land on the stones. If they fall into the river, they
    are out. The frogs was asked to jump at most m (1<= m <= n+1) times. Now the frogs want to know if they want to jump across the river, at least what ability should they have. (That is the frog's longest jump distance).

    Input

    The input contains several cases. The first line of each case contains three positive integer L, n, and m.
    Then n lines follow. Each stands for the distance from the starting banks to the nth stone, two stone appear in one place is impossible.

    Output

    For each case, output a integer standing for the frog's ability at least they should have.

    Sample Input

    6 1 2
    2
    25 3 3
    11
    2
    18

    Sample Output

    4
    11

    青蛙要在要求步数能过河,求青蛙最小的最大跳跃能力,二分;因为这个判断比较麻烦,弄错好久

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include <iomanip>
    #include<cmath>
    #include<float.h> 
    #include<string.h>
    #include<algorithm>
    #define sf scanf
    #define pf printf
    #define pb push_back
    #define mm(x,b) memset((x),(b),sizeof(x))
    #include<vector>
    #include<map>
    #define for(i,a,b) for(int i=a;i<b;i++)
    typedef __int64 ll;
    typedef long double ld;
    typedef double db;
    const ll mod=1e12+100;
    const db e=exp(1);
    using namespace std;
    const double pi=acos(-1.0);
    int a[500005],l;
    int n,m;
    bool judge(int mid)
    {
    	int ans=0,last=0;
    	if(a[0]>mid) return false;
    	for(i,0,n)
    	{
    		if(a[i+1]-a[i]>mid) return false;
    		if(a[i]-last==mid)
    		{
    			ans++;
    			last=a[i];
    		}else if(a[i+1]-last>mid)
    		{
    			ans++;
    			last=a[i];
    		}
    	}
    	ans++;
    	if(ans<=m) return true;
    	return false;
    }
    int main()
    {
    //	freopen("output1.txt", "r", stdin);
    	while(~sf("%d%d%d",&l,&n,&m))
    	{
    		int left=0,right=l,mid;
    		for(i,0,n)
    			sf("%d",&a[i]);
    		a[n]=l;
    		sort(a,a+n); 	
    		while(right-left>1)
    		{
    			mid=(left+right)/2;
    			if(judge(mid))
    			right=mid;
    			else
    			left=mid;
    		}
    		while(!judge(left)) left++;
    		pf("%d
    ",left);
    	}
    	return 0;
    }
    
  • 相关阅读:
    搞破坏(手动滑稽),如何写出让同事无法维护的代码?
    我们公司是如何把项目中的2100个if-else彻底干掉的
    为什么阿里规定需在事务注解@Transactional中指定rollbackFor?
    算法导论 10.2-7
    算法导论 10.2-3
    算法导论 10.2-2
    算法导论 10.1-7
    算法导论 10.1-6
    算法导论 2.3-7
    算法导论 2.3-5 二分查找
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9383346.html
Copyright © 2011-2022 走看看