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.

InputThe 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. 
OutputFor each point in the input, write the number written at that point or write No Number if there is none. 
Sample Input

  1. 3
  2. 4 2
  3. 6 6
  4. 3 4

Sample Output

  1. 6
  2. 12
  3. No Number
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int t;
  8. int x,y;
  9. scanf("%d",&t);
  10. while(t--)
  11. {
  12. scanf("%d%d",&x,&y);
  13. if(x==y+2||x==y)//2条线所在
  14. {
  15. if(x%2==1)//分奇偶找规律
  16. printf("%d\n",(x+y)-1);
  17. else if(x%2==0)
  18. printf("%d\n",x+y);
  19. }
  20. else
  21. printf("No Number\n");
  22. }
  23. return 0;
  24. }

  

HDU 1391 number steps(找规律,数学)的更多相关文章

  1. hdu 1391 Number Steps(规律)

    题意:找规律 思路:找规律 #include<iostream> #include<stdio.h> using namespace std; int main(){ int ...

  2. HDU 4279 Number(找规律)

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

  3. hdu 4952 Number Transformation (找规律)

    题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...

  4. HDU 4861 Couple doubi(找规律|费马定理)

    Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  5. hdu 5241 Friends(找规律?)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  6. hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...

  7. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  8. LightOj 1245 --- Harmonic Number (II)找规律

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1245 题意就是求 n/i (1<=i<=n) 的取整的和这就是到找规律的题 ...

  9. HDU 5703 Desert (找规律)

    题意:一杯水有n的容量,问有多少种方法可以喝完. 析:找规律,找出前几个就发现规律了,就是2的多少次幂. 代码如下: #include <cstdio> #include <stri ...

随机推荐

  1. c# IList<T> 深拷贝

    class A { public string a1{get;set}; public string a2{get;set}; public IList<B> a3{get;set}; / ...

  2. [Leetcode] text justification 文本对齐

    Given an array of words and a length L, format the text such that each line has exactly L characters ...

  3. HDU 多校对抗第三场 L Visual Cube

    Problem L. Visual Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java ...

  4. 编译 openssl 0.9.8zc 出现 error C2220: warning treated as error - no 'object' file generated

    remove the /WX option from CFLAG

  5. (转)HTTP请求中URL地址的编码和解码

    HTTP请求中,类似   http%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml%2Fv3Jump.html  的地址 如何解码成    http://www ...

  6. JS向右弹出DIV,点击可向左隐藏。我用jquery可以从左下角像右上角隐藏,怎么从做向右隐藏呢?

    弹出的DIV如果是绝对定位,就用right固定位子,如果不是就用float:right:Jquery中有个函数animate是自定义动画效果,$("#shou").click(fu ...

  7. js如何弹出新窗口

    js如何弹出新窗口 时间:2012-4-22 弹出新窗口也是在网页设计中会经常用到的,其用法也很简单,是通过调用javascript的内置函数windows.open来产生的.  window.ope ...

  8. 按小时或天切割Nginx日志

    #按小时或天切割Nginx日志到备份文件夹 LOGS_PATH=/home/www/logs/thc SAVE_PATH=/home/www/logs/thc YESTERDAY=$(date -d ...

  9. request.getParameterValues与request.getParameter的区别

    一. 简单的对比 request.getParameter用的比较多,相对熟悉 request.getParameterValues(String   name)是获得如checkbox类(名字相同, ...

  10. [bzoj4515][Sdoi2016]游戏-树链剖分+李超线段树

    Brief Description Alice 和 Bob 在玩一个游戏. 游戏在一棵有 n 个点的树上进行.最初,每个点上都只有一个数字,那个数字是 123456789123456789. 有时,A ...