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.

演示样例输入

3
4 2
6 6
3 4

演示样例输出

6
12
No 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 long
using 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);
else
printf("%d\n",2*x);
}
else if(y==x-2)
{
if(x%2)
printf("%d\n",2*x-3);
else
printf("%d\n",2*x-2);
}
else
puts("No Number");
}
return 0;
}


SDUT 1068-Number Steps(数学:直线)的更多相关文章

  1. HDU-1391 Number Steps

    http://acm.hdu.edu.cn/showproblem.php?pid=1391 Number Steps Time Limit: 2000/1000 MS (Java/Others)   ...

  2. Number Steps

    Number Steps Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  3. ZOJ 1414:Number Steps

    Number Steps Time Limit: 2 Seconds      Memory Limit: 65536 KB Starting from point (0,0) on a plane, ...

  4. POJ 1663:Number Steps

    Number Steps Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13758   Accepted: 7430 Des ...

  5. POJ 1663:Number Steps

    Number Steps Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13664   Accepted: 7378 Des ...

  6. HDU 1391 number steps(找规律,数学)

    Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,... as shown ...

  7. SDUT 3258 Square Number 简单数学

    和上一题一样,把平方因子除去,然后对应的数就变成固定的 #include <cstdio> #include <iostream> #include <algorithm ...

  8. SDUT 3257 Cube Number 简单数学

    把所有数的立方因子除去,那么一个数可以和它组成立方的数是确定的,统计就行 #include <cstdio> #include <iostream> #include < ...

  9. hdu1391(Number Steps )

    Problem Description Starting from point (0,0) on a plane, we have written all non-negative integers ...

  10. HDU 1018-Big Number(数学)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

随机推荐

  1. oracle主键自增长

    这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下: create table simon_example ( id number(4) not null primary key, nam ...

  2. iOS学习笔记38-MJExtension使用

    一.MJExtension第三方框架 我们在iOS开发过程中,我们常常需要将字典数据(也就是JSON数据)与Model模型之间的转化,例如网络请求返回的微博数据.等等,如果我们自己全部手动去创建模型并 ...

  3. 如何在c#代码中执行带GO语句的SQL文件

      需要在C#代码中执行一个SQL文件的内容.遇到了两个问题: 1. 因为SQL文件中有"GO"语句,执行时报错"Incorrect syntax near 'GO'.& ...

  4. Python Base Three

    //sixth day to study python(2016/8/7) 32. In python , there are have an special type dictionary , it ...

  5. Javascript 开启浏览器全屏模式

    作者:伯乐在线/前端空城师 通常在某些情况下,我们需要让浏览器开启全屏模式,以便获得更好的视觉体验,先看下全屏模式简单的几个API. 浏览器默认绑定 非全屏模式下, document的F11按键绑定开 ...

  6. 转 Python爬虫入门七之正则表达式

    静觅 » Python爬虫入门七之正则表达式 1.了解正则表达式 正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串 ...

  7. [Machine Learning with Python] Familiar with Your Data

    Here I list some useful functions in Python to get familiar with your data. As an example, we load a ...

  8. 公司内部技术分享之Vue.js和前端工程化

    今天主要的核心话题是Vue.js和前端工程化.我将结合我这两年多的工作学习经历来谈谈这个,主要侧重点是前端工程化,Vue.js侧重点相对前端工程化,比重不是特别大. Vue.js Vue.js和Rea ...

  9. Xamarin.Forms的ActivityIndicator和ProgressBar比较

    Xamarin.Forms的ActivityIndicator和ProgressBar比较   在Xamarin.Forms中,控件ActivityIndicator和ProgressBar都用来表示 ...

  10. inotify+rsync实现实时同步(附解决crontab中无法执行python脚本的问题)

    1.准备环境 # 系统支持的话,下面的目录就会存在 ls /proc/sys/fs/inotify/ rpm -qa inotify-tools yum -y install inotify-tool ...