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...10000.
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.
Example
Input:
3
4 2
6 6
3 4
Output:
6
12
No Number
本程序优雅的地方就是充分考虑好各种情况,然后合并起来,代码就简洁了
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void NumberSteps()
{
int T = 0;
cin>>T;
int x = 0, y = 0;
while (T--)
{
cin>>x>>y;
if (x != y && y+2 != x) cout<<"No Number"<<endl;
else
{
if (x % 2) cout<<x+y-1<<endl;
else cout<<x+y<<endl;
}
}
}
int main()
{
NumberSteps();
return 0;
}
分享到:
相关推荐
Some Solution of Problem in SPOJ (Sphere Online Judge) solved in various algorithm.
My solution for some spoj problems
SPOJ解决方案 我已解决的SPOJ问题的解决方案。 仅当您自己尝试过该问题并且无法提出任何解决方案,也可以随意报告任何错误并为该存储库提供解决方案时,才请参考这些解决方案。 我的个人资料链接 会费 分叉仓库并为...
SPOJ-Solutions:SPOJ算法问题的解决方案
RandomGoCode:算法,SPOJ,涂鸦...但是在Go中!
) :red_heart:附Oj平台平台地址BZOJ POJ 硬盘单元洛谷 代码VS 牛编码器 LibreOJ 编码部队 51点头 编码器 上海交大 最佳编码器 卢特斯 华东师范大学 SPOJ 宁波奥杰 Darkbzoj 虚拟法官 上下文猎人 维霍斯 公开评委小...
SPOJ-备份工具 介绍 在 Sphere Online Judge ( ) 中,您可以尝试所给的具有挑战性的问题。 它还使您能够查看和下载您自己的解决方案。 工具 SPOJ_BACKUP 备份所有已接受的提交并将它们保存在脚本所在的计算机位置。...
SPOJ-解决方案复合解决方案
SPOJ-解决方案SPOJ问题的解决方案,主要是java一些python。
Spoj-解决方案 我的连接解决方案
Spoj 用户工具基于 Django 的 Spoj 用户分析工具。 目前托管在 Google Appengine 上: ://spojtool.appspot.com/安装获取列出的包,并将它们放在指定的项目目录中。 为了安全,请修改 secret_key.py 中的 SECRET_KEY...
Spoj-解决方案 此存储库包含 spoj 问题的解决方案。 问题是通过他们的 id 来识别的。
SPOJ题库( http://www.spoj.pl)的离线题库。 包括索引+内容。PDF格式。 主要是Classical的problemset。
SPOJ解决方案 最好的:我的SPOJ
Judge-允许使用各种各样的编程语言【SPOJ】 http://www.spoj.pl/ SGU Online Contester-具有模拟参加历史比赛的虚拟赛功能 http://acm.sgu.ru/ Codeforces-不断维护历届题库 http://codeforces.com 首先,...
SPOJ 应对spoj.com的挑战
竞技编程这个 repo 包含(几乎)所有程序: codechef.com codeforces.com 间谍网黑客等级网Hande : sananth12 在所有平台上统计数据代码总行数:22,410+ 程序总数:500+
我在C ++中针对Spoj托管的一些问题的解决方案 :laptop: 编码BUGLIFE 埃及披萨丽莎NFURY PT07Y TRT 地址BVAAN EKO LPIS 纽约10E PT07Z TWENDS 阿格罗夫CAM5 电动车MAIN12A ORDSUM23 里瓦尔斯ULM09 爱宝CODERE3 前脸...
复合溶液简单的CONNECT问题的解决方案。 参见: :
SPOJ调整在SPOJ网站上进行细微调整的Chrome扩展程序,在很大程度上基于的先前工作进行了调整,以适应网站的新布局。特征经典问题在问题集中的“用户”列旁边有一个“分数”列。 点数显示在经典问题的标签下,挑战...