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.
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
- SDUT 1068-Number Steps(数学:直线)
- SDUT 2623:The number of steps
- 【CodeForces 804B】Minimum number of steps(思维+数学)
- SDut 3257 Cube Number && SDUT 3258 Square Number 超详细题解(数学)
- sdut 2623 The number of steps (概率dp)
- [2013山东ACM省赛] The number of steps (概率DP,数学期望)
- UVA 846 - Steps(数学)
- Number Steps
- Number Steps
- Number Steps
- Number Steps
- Number Steps
- Number Steps
- Number Steps
- uva 846 Steps(数学规律)
- zoj 1871 steps 题解(数学)
- zoj 1414 Number Steps(水~)
- 【POJ】1663 - Number Steps(找规律)
- 在web.xml中配置servlet定义
- Git 历险记
- 无聊的黑叔
- [Django]models中定义的choices 字典在页面中显示值
- [无限互联]学员作品:旅游软件“在路上”IOS客户端
- SDUT 1068-Number Steps(数学:直线)
- poj2406--Power Strings(KMP求最小循环节)
- poj 3921 (控制费用的 最小割)
- Struts 2的工作流程
- html使用列表 以及div的布局和table的布局
- HDOJ题目1505 City Game(动态规划)
- Java 学习 第三章 Java核心-继承与多态
- ANDROID L——Material Design详解(视图和阴影)
- struts2的优点