杭电OJ题 1391 Number Steps 解题报告
来源:互联网 发布:淘宝韩版女装店铺推荐 编辑:程序博客网 时间:2024/05/29 18:27
Number Steps
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2697 Accepted Submission(s): 1656
Total Submission(s): 2697 Accepted Submission(s): 1656
Problem Description
Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,... as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has continued.
You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...5000.
You are to write a program that reads the coordinates of a point (x, y), and writes the number (if any) that has been written at that point. (x, y) coordinates in the input are in the range 0...5000.
Input
The first line of the input is N, the number of test cases for this problem. In each of the N following lines, there is x, and y representing the coordinates (x, y) of a point.
Output
For each point in the input, write the number written at that point or write No Number if there is none.
Sample Input
34 26 63 4
Sample Output
612No Number
——————————————————————————————————————————————————————————
主要是找规律。当x==y时 当x是偶数时,为x*2,如果是奇数时,为2*n-1,其他的数的话如果y < x,则为y==x时的数减去2就行了
/************************ 程序名:Number Steps.c* 功能:ACM************************/#include <stdio.h>int main(){ int N, x, y; scanf("%d", &N); while(N--) { scanf("%d %d", &x, &y); if(x == y || x - y == 2) { if(x == y) { if(x % 2 == 0) { printf("%d\n", x*2); } else { printf("%d\n", x*2-1); } } else { if(x % 2 == 0) { printf("%d\n", x*2-2); } else { printf("%d\n", x*2-3); } } } else { printf("No Number\n"); } } return 0;}
- 杭电OJ题 1391 Number Steps 解题报告
- 杭电OJ题 1562 Guess the number解题报告
- 杭电OJ题1018 Big Number 解题报告
- 杭电1391 Number Steps
- 杭电OJ 1209题clock 解题报告
- 杭电OJ题 1106 排序 解题报告
- 杭电OJ 题 1209 Clock 解题报告
- 杭电OJ题 1236 排名 解题报告
- 杭电OJ题 1347 Grandpa is Famous解题报告
- 杭电OJ题 1361 Parencodings解题报告
- 杭电OJ题 1379 DNA Sorting解题报告
- 杭电OJ题 1390 Binary Numbers解题报告
- 杭电OJ题 1393 Weird Clock解题报告
- 杭电OJ题 Goldbach's Conjecture解题报告
- 杭电OJ题 1408 盐水的故事 解题报告
- 杭电OJ题 1412 {A} + {B} 解题报告
- 杭电OJ题 1444 Maya Calendar解题报告
- 杭电OJ题 1491 Octorber 21st 解题报告
- qsort 函数的使用
- php输出、写入csv
- 在IE6里无法识别first-letter/:first-line?
- Application cannot be run in virtual machine.
- Codeforces Round #154 (Div. 2)
- 杭电OJ题 1391 Number Steps 解题报告
- 初始化条件变量pthread_cond_init
- Hibernate 之 Persistence
- GNU C
- struts2.1.6 + hibernate3.3 + spring3.0 遇到的问题
- Android入门(5) XML
- Oracle 分页的三种情况
- Android 学习 应用使用大文件的方法 读取sd卡的数据库
- POJ3267