博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu1391(Number Steps )
阅读量:7282 次
发布时间:2019-06-30

本文共 1294 字,大约阅读时间需要 4 分钟。

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.
 

 

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
3 4 2 6 6 3 4
 

 

Sample Output
6 12 No Number
#include
int main(){ int x,y,a,t; scanf("%d",&t); while(t--) { scanf("%d%d",&x,&y); if(y==x)//上边那直线 { if(x%2==0) a=2*x; else a=1+4*((x+1)/2-1); printf("%d\n",a); } else if(y==x-2)//下边直线 { if(x%2==0) a=2*(x-1); else a=3+4*((x-1)/2-1); printf("%d\n",a); } else printf("No Number\n"); }}
 

转载地址:http://bazjm.baihongyu.com/

你可能感兴趣的文章
解决 "Script Error" 的另类思路
查看>>
前端每周清单第 55 期: MobX 4 特性概览,iOS Hacks 分享, 分布式事务详解
查看>>
前端每周清单第 53 期:Go 与 WebAssembly, React Suspense 演练, CSS 技巧
查看>>
微服务如何落地
查看>>
微内核专题系列
查看>>
利用tess-two和cv4j实现简单的ocr功能
查看>>
Http1.1客户端缓存总结以及hapi实践
查看>>
shell基础学习笔记
查看>>
【centos7.2部署第7期】jenkins+github+nodejs+pm2实现持续集成
查看>>
JavaScript数组的十八般武艺
查看>>
用 Python 写脚本发送工作周报
查看>>
程序员算法练习四
查看>>
搭建本地 mock 服务
查看>>
iOS笔记:进一步认识 ==、isEqual、hash
查看>>
通过 recompose 实现 react router4 权限
查看>>
逻辑思维训练
查看>>
【Golang实现文件服务器】(一)初始版本
查看>>
8年资深测试工程师如何提交有效缺陷
查看>>
代码优化常用方法
查看>>
OkHttp深入分析——基础认知部分
查看>>