Steps
uva846:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=787
题意:给你两个数x,y,x<=y,现在让你从x走向y,开始的第一次和最后一次,只能够移动一步,之后每一次走的步数和上次走的步数之和之差不超过1.问你到达y最小需要多少步。
题解:从x,y同时开始走,每次步数加一,如果走到两者刚好相遇则停止,如果剩余的距离不超过当前的步数,也可以停止,因为这剩余的距离可以在之前的某个时间段走完,相当于在之前走了一个水平的阶段。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int x,y;
int main(){
int cas;
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&x,&y);
int counts=,step=;
while(){
if(x>=y){
printf("%d\n",*counts);
break;
}
if(y-x<=step){
printf("%d\n",*counts+);
break;
}
else{
x+=step;
y-=step;
counts++;
step++;
}
}
}
}
Steps的更多相关文章
- animation-timing-function: steps() 详解
在应用 CSS3 渐变/动画时,有个控制时间的属性 <animation-timing-function> .它的取值中除了常用到的 贝萨尔曲线以外,还有个让人比较困惑的 steps() ...
- CSS3 Animation 帧动画 steps()
@keyframes fn{ 0%{} 100%{} } CSS3的Animation有八个属性 animation-name :动画名 fn animation-duration:时间 1s ani ...
- SAML 2.0 setup steps, 效果图
Steps of setting up SAML SSO. 效果图 # Registry a Identity Provider services in:(Might need purchase) I ...
- 【译】css动画里的steps()用法详解
原文地址:http://designmodo.com/steps-c... 原文作者:Joni Trythall 我想你在css 动画里使用steps()会和我一样有很多困惑.一开始我不清楚怎样使用它 ...
- css3动画中的steps值详解
css3的动画的animation-timing-function属性定义了动画的速度曲线,一般的速度曲线大家都知道,什么ease,linear,ease-in,ease-out,还有自定义贝塞尔曲线 ...
- steps animation
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- sdutoj 2623 The number of steps
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2623 The number of steps ...
- SAP NWBC for HTML and Desktop configuration steps[From sdn]
Summary :- This dcoumnenst conatin the information about requirement , hardware , configuration step ...
- 【转载】7 Steps for Calculating the Largest Lyapunov Exponent of Continuous Systems
原文地址:http://sprott.physics.wisc.edu/chaos/lyapexp.htm The usual test for chaos is calculation of the ...
- BSGS算法_Baby steps giant steps算法(无扩展)详解
Baby Steps-Varsity Giant Step-Astronauts(May'n・椎名慶治) 阅读时可以听听这两首歌,加深对这个算法的理解.(Baby steps少女时代翻唱过,这个原唱反 ...
随机推荐
- xargs 参数
hadoop fs -ls /source/recommend/at_access | awk -F "/" '{print $NF}' | grep -v $(date +%Y% ...
- 编写一个方法,输入DOM节点,返回包含所有父节点的一个数组
编写一个方法,输入DOM节点,返回包含所有父节点的一个数组 function getParentsNodes(element) { var parents = []; var getParentsNo ...
- c#简单数组
int[,] a=new int[,]{{1,2},{3,4},{5,6}};//二维数组 textbox.text=a[0,1];//=2 int[][] b={new int[]{1,2},new ...
- 关于Form窗体的StartPosition 属性如何设置的问题
1.让窗体在启动时在指定位置出现 form1.StartPosition Manual CenterScreen WindowsDefaultLocation (default) WindowsDef ...
- 【技术文档】《算法设计与分析导论》R.C.T.Lee等·第4章 分治策略
分治策略有一种“大事化小,小事化了”的境界,它的思想是将原问题分解成两个子问题,两个子问题的性质和原问题相同,因此这两个子问题可以再用分治策略求解,最终将两个子问题的解合并成原问题的解.有时,我们会有 ...
- 辛星浅析跨域传输的CORS解决方式
首先我们有一个概念.那就是"同源准则",也就是same-origin policy,它要求一个站点(协议+主机+port号)来确定的脚本.XMLHttpRequest和Webso ...
- 1031. Hello World for U (20)
题目链接:http://www.patest.cn/contests/pat-a-practise/1031 题目: 分析: 排版题.注意先计算好最后一排的字符数,然后计算前面几排的空格数.难度不大 ...
- [Angular 2] Use Service use Typescript
When creating a service, need to inject the sercive into the bootstrap(): import {bootstrap, Compone ...
- mac缺少预编译.a问题
在win7的svn提交了coco2d-x 3.0代码,在mac进行更新,用xcode打开工程,编译不成功,一看好多的.a文件全部都是红色的,无法找到文件,一开始不了解coco2d-x的prebuilt ...
- 獲取 Textarea 的光標位置(摘自網絡)
在任何编辑器中,获取光标位置都是非常重要的,很多人可能认为较难,其实只要处理好浏览器的兼容,还是比较容易实现的.下面我们一起来看看如何获取到 Textarea 元素中的光标位置.首先,我们用 rang ...