Problem Description
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.

 
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.

 
Sample Input
3
4 2
6 6
3 4
 
Sample Output
6
12
No Number
#include<stdio.h>
int main()
{
int x,y,a,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&x,&y);
if(y==x)//上边那直线
{
if(x%2==0)
a=2*x;
else
a=1+4*((x+1)/2-1);
printf("%d\n",a);
}
else if(y==x-2)//下边直线
{
if(x%2==0)
a=2*(x-1);
else
a=3+4*((x-1)/2-1);
printf("%d\n",a);
}
else
printf("No Number\n");
}
}

 

hdu1391(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. HDOJ 1391 Number Steps(打表DP)

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

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

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

  8. 九度OJ 1136:Number Steps(步数) (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:691 解决:412 题目描述: Starting from point (0,0) on a plane, we have written ...

  9. hdu 1391 Number Steps(规律)

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

随机推荐

  1. 【Android】: 部分注意事项

    1.用来触发BroadcastReceive的Intent和启动Activity或Service的Intent是不兼容的. 2.当文件名做为ContentProvider查询的一部分返回的时候,不应该 ...

  2. 【图文】雪佛兰Suburban 美国特工标准座驾_新闻中心_易车网

    [图文]雪佛兰Suburban 美国特工标准座驾_新闻中心_易车网 雪佛兰Suburban 美国特工标准座驾

  3. Part Acquisition(spfa输出路径)

    Part Acquisition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4080   Accepted: 1742 ...

  4. SqlServer和Oracle中一些常用的sql语句10 特殊应用

    --482, ORACLE / SQL SERVER --订购数量超过平均值的书籍 WITH Orders_Book AS ( SELECT Book_Name, SUM(Qty) Book_Qty ...

  5. [HDU 1428]--漫步校园(记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1428 漫步校园 Time Limit: 2000/1000 MS (Java/Others)    M ...

  6. 树莓派做web服务器(nginx、Apache)

    一想到Linux Web服务器,我们首先想到的是: Apache + MySql + Php. Apache:是世界使用排名第一的Web服务器软件. 可以运行在几乎所有广泛使用的计算机平台上,由于其跨 ...

  7. 面向对象程序设计-C++ Steam & Vector 【第三次上课笔记】

    大家可以下载后用Vim 或者 Sublime Text等文本编辑器查看 Conference: http://blog.csdn.net/candy1232009/article/details/70 ...

  8. Base64编码的java实现

    Java本身是提供了Base64编码的工具包的,做项目的时候自己实现了个,在这里记录一下: /** Base64编码数组 */ private static final String base64En ...

  9. DW8051调试终结

    都不记得自己到底揪心了多久 —— 归根结底还是自己太菜了.终于找到了DW8051移植的bug. 这么大的一个图居然没有看到,真是气煞老夫也. 在原来移植的基础之上加两个反相器就OK 了

  10. 疯牛-- Aggressive cows (二分)

    疯牛 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小 ...