首页 > 试题广场 >

Number Steps

[编程题]Number Steps
  • 热度指数:5139 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
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.

输入描述:
each line, there is x, and y representing the coordinates (x, y) of a point.


输出描述:
For each point in the input, write the number written at that point or write No Number if there is none.
示例1

输入

3
4 2
6 6
3 4

输出

6
12
No Number
头像 健康快乐最重要
发表于 2020-03-05 13:06:16
找规律(很简单的规律):1.如果x+y是奇数或者(x-y!=0&&x-y!=2)输出no number。2.如果不满足上面条件则,y是奇数输出x+y-1,否则输出x+y。 #include<iostream> #include<vector> using na 展开全文
头像 牛客440904392号
发表于 2024-09-29 23:05:42
//Java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); 展开全文
头像 拒绝内卷plus
发表于 2024-03-14 21:53:35
#include <stdio.h> int f1(int x,int y) { if(x%2==0) return x*2-2; return x*2-3; } int f2(int x,int y) { if(x%2==0) return x+ 展开全文
头像 粉詹眉
发表于 2024-02-21 00:39:19
#include <iostream> using namespace std; //题目很坑,根本就没有n,只需输入x,y即可 int main() { int x, y; while (cin >> x >> y) { if 展开全文
头像 lyw菌
发表于 2023-03-11 16:43:28
//看了三遍才看明白,其实就是找规律。给你一个点的坐标(x,y),输出此坐标所表示的值。 //eg:(2,0)为2而(3,0)不存在所以为No Number。所以就是找规律,规律也很好找。 //若x为偶数,则为x+y(注意判断不存在数的点)。x若为奇数,则为x+y-1(注意判断不存在数的点). #i 展开全文
头像 chong_0428
发表于 2025-02-17 00:15:49
#n = int(input()) a = 2 b = 0 c1 = 0 c = 0 #for i in range(n): x, y = list(map(int, input().split())) if x == 0 and y == 0: print(0) elif x == 2 展开全文
头像 i惠风和畅
发表于 2024-03-23 13:27:39
#include <iostream> using namespace std; int main() { int x = 0; int y = 0; while (cin >> x >> y){ if (y == x 展开全文
头像 i惠风和畅
发表于 2024-03-23 13:29:08
#include <iostream> using namespace std; int main() { int x = 0; int y = 0; while (cin >> x >> y){ if (y == x 展开全文
头像 挂耳coffe
发表于 2025-03-18 21:46:46
#include <iostream> using namespace std; int main() { int x, y; while (cin >> x >> y) { if (x == y) { i 展开全文
头像 陶良策
发表于 2025-02-22 11:20:59
#include <iostream> using namespace std; int main() { int x,y,k; while (scanf("%d %d",&x,&y)!=EOF) { // 注意 while 处理多个 展开全文