SDUT 1068-Number Steps(数学:直线)

来源:互联网 发布:微信群淘宝客机器人 编辑:程序博客网 时间:2024/04/30 12:33

Number Steps

Time Limit: 1000ms   Memory limit: 10000K  有疑问?点这里^_^

题目描述

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.

输入

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.

输出

For each point in the input, write the number written at that point or write No Number if there is none.

示例输入

34 26 63 4

示例输出

612No Number
就是按图中的规律给出两条直线。。我一开始居然没看出来是直线。。找规律打表敲了一大片结果wa了,后来发现就是判断点是否在直线上嘛 两条直线分别为y=x与y=x-2; 然后那个编号可以根据坐标x写出对应关系,很好写,都是等差数列,我是分奇偶讨论的。。
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cctype>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>#include <list>#define ll long longusing namespace std;const int INF=1<<27;const int maxn=1010;int main(){int x,y,n;scanf("%d",&n);while(n--){scanf("%d%d",&x,&y);if(x==y){if(x%2)printf("%d\n",2*x-1);elseprintf("%d\n",2*x);}else if(y==x-2){if(x%2)printf("%d\n",2*x-3);elseprintf("%d\n",2*x-2);}elseputs("No Number");}    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 济宁社保卡丢了怎么办 农村医疗本丢了怎么办 常熟医保卡丢了怎么办 农民社保卡丢了怎么办 常熟社保卡坏了怎么办 社保卡丢失补办期看病怎么办 社保卡补办期间看病怎么办 医保卡冻结了出院结算怎么办 住院医保卡钱不够怎么办 住院押金条丢了怎么办 急用新社保卡要怎么办 看病没带社保卡怎么办 医保卡掉了住院怎么办 厦门医保卡丢了怎么办 成都医保卡丢了怎么办 长春医保卡丢了怎么办 县城医保卡丢了怎么办 医保卡丢了怎么办南宁 西安职工医保丢了怎么办 重庆医保卡丢了怎么办 外地医保卡丢了怎么办 换单位后医保卡怎么办 单位没交失业金怎么办 沈阳医保卡密码忘了怎么办 西安网约车资格证怎么办 红跑车卡丢了怎么办 苏州住房公积金密码忘了怎么办 公积金查询密码忘记了怎么办 公积金账户密码忘记了怎么办 公积金网上查询密码忘记了怎么办 苏州改公积金密码忘了怎么办 与单位解除劳动合同公积金怎么办 在泰国钱包丢了怎么办 中山车牌网上选号后怎么办 买楼房70年以后怎么办 暂住证过期2个月怎么办 换领驾驶证超期了怎么办 车牌租出去要不回来怎么办 汽车放久了没电怎么办 上海网约车资格证怎么办 手机掉在滴滴上怎么办