o.boj 1022 Steps
2011-12-17 00:21
337 查看
注:最近这一系列ACM的内容,都是2年多之前的代码,自己回顾一下。
Steps
Submit: 849 Accepted:294
Time Limit: 1000MS Memory Limit: 65536K
Description
One steps through integer points of the straight line. The length of a step must be nonnegative and can be by one bigger than, equal to, or by one smaller than the length of the
previous step.
What is the minimum number of steps in order to get from x to y? The length of the first and the last step must be 1.
Input
Input consists of a line containing n, the number of test cases.
Output
For each test case, a line follows with two integers: 0 <= x <= y < 2^31. For each test case, print a line giving the minimum number of steps to get from x to y.
Sample Input
3
45 48
45 49
45 50
Sample Output
3
3
4
Source
Waterloo local 2000.01.29
从题目便可以知道,在已知步数的情况下,最多可以走多少的距离。本时不卡时间,直接从步数从少到大计算最长距离是与跟已知条件的距离相等,即可。
[/code]
Steps
Submit: 849 Accepted:294
Time Limit: 1000MS Memory Limit: 65536K
Description
One steps through integer points of the straight line. The length of a step must be nonnegative and can be by one bigger than, equal to, or by one smaller than the length of the
previous step.
What is the minimum number of steps in order to get from x to y? The length of the first and the last step must be 1.
Input
Input consists of a line containing n, the number of test cases.
Output
For each test case, a line follows with two integers: 0 <= x <= y < 2^31. For each test case, print a line giving the minimum number of steps to get from x to y.
Sample Input
3
45 48
45 49
45 50
Sample Output
3
3
4
Source
Waterloo local 2000.01.29
从题目便可以知道,在已知步数的情况下,最多可以走多少的距离。本时不卡时间,直接从步数从少到大计算最长距离是与跟已知条件的距离相等,即可。
#include <stdio.h> #include <stdlib.h> main() { int count, n, x, y, distance, sum; int i; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &x, &y); distance = y - x; count = 0; sum = 0; while (sum < distance) { if (count % 2 == 0) sum = (count/2 + 1) * count/2; else sum = (count/2 + 1) * (count/2 + 1); count ++; } if (count) count --; printf("%d\n", count); } // system("pause"); return 0; }
[/code]
相关文章推荐
- o.boj 1022 SuperRock钟爱的香蕉
- handle leak ts steps in chinese
- ActiveBPEL引擎(4.0)启动步骤分析(ActiveBPEL Engine Startup Steps)
- From Java to Groovy in a few easy steps
- Developing Workflows in VS: Part 3 - Five Steps for Developing Your Workflow
- Steps in the Emergency Performance Method
- ORACLE E B S DATABASE CLONE steps
- [转]3 Quick Steps for a Painless Upgrade to jQuery 1.3
- Seven Steps to Test Automation Success
- 1022
- [Stax] The steps of installing stax in Ubuntu 10.04
- boj problem 1323 读取字符串时候要考虑空格情况 用cin.getline(数组名,大小)
- boj 1336 简单的问题 不过自己没想到 别人解释的~~学习~~这个是 第二类Stirling数 需要再好好看看
- boj 1204 让树的根结点到叶子结点等长的问题
- Steps to Re-Create ASM Diskgroups
- BOJ1018 -- Airline Hub
- HDU 1022 Train Problem I
- 08-31 HDU_Steps2.1 HDU1108 HDU2138 HDU1713 HDU1722 HDU2136 HDU2504 HDU1286 HDU1717
- 09-08 HDU_Steps5.2 字典树,拓扑,哈夫曼 HDU1075 HDU1251 HDU1671 HDU1285 HDU2094 HDU3231 HDU1053 HDU2527
- hdu acm steps 1.3.6