zoukankan      html  css  js  c++  java
  • zoj1871steps 数学 水

                                                                                            zoj1871
    题目大意:给你一段长度,起始和末尾一步只能是一个单位长度,每一步和前一步长度差不超过一,问恰好走到终点的最小步数。
    假设前半截一直在+1,后半截直接对称过去,刚刚到则+0,保证了最小步数,剩余的零头+1或者+2.

    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    using namespace std;
    int main()
    {
    	int m,n,temp,i;
    	while(~scanf("%d%d",&m,&n)){
    		temp=0;
    	    m=n-m;;
    		i=1;
    		while(true)
    		{
    			temp+=2*i;
    			if(temp+2*(i+1)<=m) i++;
    			else break;
    		}
    		if(temp==m) printf("%d
    ",2*i);//刚刚到 
    		else if(temp+i>=m) printf("%d
    ",2*i+1);//单出来一次 
    		else printf("%d
    ",2*i+2);//单出来两次 
    	}
    	return 0;
    }


  • 相关阅读:
    Pull Request
    选择器
    常见HTTP状态码
    286. Walls and Gates
    200. Number of Islands
    1. Two Sum
    名片管理系统(python实现)
    k近邻算法(简单版)
    基数排序
    递归算法的调试
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7603961.html
Copyright © 2011-2022 走看看