HDOJ - 4004 The Frog's Games

The Frog's Games
Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64u

Description

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

大致题意:青蛙通过河里的石头跳到对岸,河长L,河里有石头N块,最多只能跳M次。每个石块到岸边的距离已给出,求青蛙跳的最短距离。
解题报告:很明显河里的石头距离岸边的长度是递增的,青蛙不可能来回跳!所以可用二分来处理。刚做的时候一脸懵逼,毫无头绪,看了别人的集体思路,一点点弄明白了。。如果青蛙连两块石头间的最远距离都跳不到,它是不可能到对岸的,所以左区间应从最远距离开始。
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,d[500001];
int sum(int mid){	
    int i,j,k=0,y=0;
    for(i=1;i<n+2;i++){
        y+=d[i]-d[i-1];//y代表从岸边跳到第i个石头上所用的距离  
        if(y>mid){//当y大于mid时,可以mid跳到前一个石头上 
			y=d[i]-d[i-1];//再次从第i个开始累计 
			k++;// 需要跳的次数  
		}
    }
    return y>mid?1<<30:k+1;//1<<30即2^30,如果y>mid,说明最后不能跳到对岸 
}
int main(){
    int l,left,right,i,j,k,mid,x,s;
    while(~scanf("%d%d%d",&l,&n,&m)){
        for( i=1;i<=n;i++)
        	scanf("%d",&d[i]);
        d[n+1]=l;//整条河的长度 
        d[0]=0;	
        sort(d+1,d+n+1);
        for(i=1,j=0;i<n+2;i++)
        	if(j<d[i]-d[i-1])
        		j=d[i]-d[i-1];//两点之间的最远距离
        left=j;right=l;//最远距离为左区间 
        while(left<right){//开始二分 
            mid=(left+right)/2;
            if(sum(mid)<=m)
				right=mid;// 右区间能取到mid!因为从左端起跳,临界状态 
            else
				left=mid+1;
        }
        printf("%d\n",left);
    }
    return 0;
}
一、综合实战—使用极轴追踪方式绘制信号灯 实战目标:利用对象捕捉追踪和极轴追踪功能创建信号灯图形 技术要点:结合两种追踪方式实现精确绘图,适用于工程制图中需要精确定位的场景 1. 切换至AutoCAD 操作步骤: 启动AutoCAD 2016软件 打开随书光盘中的素材文件 确认工作空间为"草图与注释"模式 2. 绘图设置 1)草图设置对话框 打开方式:通过"工具→绘图设置"菜单命令 功能定位:该对话框包含捕捉、追踪等核心绘图辅助功能设置 2)对象捕捉设置 关键配置: 启用对象捕捉(F3快捷键) 启用对象捕捉追踪(F11快捷键) 勾选端点、中心、圆心、象限点等常用捕捉模式 追踪原理:命令执行时悬停光标可显示追踪矢量,再次悬停可停止追踪 3)极轴追踪设置 参数设置: 启用极轴追踪功能 设置角度增量为45度 确认后退出对话框 3. 绘制信号灯 1)绘制圆形 执行命令:"绘图→圆→圆心、半径"命令 绘制过程: 使用对象捕捉追踪定位矩形中心作为圆心 输入半径值30并按Enter确认 通过象限点捕捉确保圆形位置准确 2)绘制直线 操作要点: 选择"绘图→直线"命令 捕捉矩形上边中点作为起点 捕捉圆的上象限点作为终点 按Enter结束当前直线命令 重复技巧: 按Enter可重复最近使用的直线命令 通过圆心捕捉和极轴追踪绘制放射状直线 最终形成完整的信号灯指示图案 3)完成绘制 验证要点: 检查所有直线是否准确连接圆心和象限点 确认极轴追踪的45度增量是否体现 保存绘图文件(快捷键Ctrl+S)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值