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. java学习之线程池的实现

    package com.gh.threadpoor; import java.util.concurrent.ExecutorService; import java.util.concurrent. ...

  2. 【Cavali风格/优质羊毛混纺面料/高密抗静电里衬/撞色拼皮/立领/绿色/便装单西】玛萨玛索男装网购商城

    [Cavali风格/优质羊毛混纺面料/高密抗静电里衬/撞色拼皮/立领/绿色/便装单西]玛萨玛索男装网购商城 Cavali风格/优质羊毛混纺面料/高密抗静电里衬/撞色拼皮/立领/绿色/便装单西

  3. 详解Spring

    Spring SSH框架中Struts2:是基于Web层,Hibernate:是基于持久化的,Spring:业务层,管理bean,它是一个容器,List,map, Set这里的内容,是适合已经学过了S ...

  4. UVALive 5102 Fermat Point in Quadrangle 极角排序+找距离二维坐标4个点近期的点

    题目链接:点击打开链接 题意: 给定二维坐标上的4个点 问: 找一个点使得这个点距离4个点的距离和最小 输出距离和. 思路: 若4个点不是凸4边形.则一定是端点最优. 否则就是2条对角线的交点最优,能 ...

  5. 怎样使用windows命令行,用notepad打开某文件夹下面的所有文件

    http://zhidao.baidu.com/question/2138815012359999388.html __________________________________________ ...

  6. [转] iOS应用架构谈 网络层设计方案

    原文地址:http://casatwy.com/iosying-yong-jia-gou-tan-wang-luo-ceng-she-ji-fang-an.html iOS应用架构谈 开篇 iOS应用 ...

  7. (Problem 4)Largest palindrome product

    A palindromic number reads the same both ways. The largest palindrome made from the product of two 2 ...

  8. django-model-utils

    一个普通例子: todos = Todo.objects.filter(owner=request.user).filter(is_done=False).filter(priority=1) 弊端: ...

  9. 基于visual Studio2013解决算法导论之012计数排序

     题目 计数排序 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <malloc.h> #in ...

  10. kingso_sort - Taocode

    kingso_sort - Taocode 如何编写新sort 由于排序逻辑多种多样,kingso的排序设计成是由一个个排序对象串起的排序链条组成.排序对象之间可以任意组合(只需要改配置文件),就可以 ...