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. cocos2dx进阶学习之CCLayer

    继承关系 CCLayer -> CCNode,CCTouchDelegate,CCAccelerometerDelegate,CCKeypadDelegate CCLayer在cocos2dx中 ...

  2. MFC基础,MFC自绘控件学习总结.---转

    前言:从这学期开始就一直在学习自绘控件(mfc),目标是做出一款播放器界面,主要是为了打好基础,因为我基础实在是很烂....说说我自己心得体会以及自绘控件的方法吧,算是吐槽吧,说的不对和不全的地方,或 ...

  3. myeclipse设置凝视

    Window-perferences--java--Code Style--Code Templates--Commments 类凝视:Types /** *@desc *@author haozk ...

  4. cocos2d-x3.6 连连看连通画线

    我的博客:http://blog.csdn.net/dawn_moon 网上看到非常多人写的连连看,都没有画连线的实现.事实上要话连线挺简单的.cocos2d-x 提供了一个非常方便的绘图形的类.Dr ...

  5. Fundamental types

    Fundamental types void type boolean type character types integer types Modifiers signedness size Pro ...

  6. Android线程和handler

    根据视频仿照着写了个demo: package com.wyl.wylthreadtest; import android.graphics.Color; import android.os.Bund ...

  7. [转] 解析LayoutSubviews

    转自: http://www.cnblogs.com/YouXianMing/p/3897543.html 从百度上搜索了一下layoutSubviews的用处,以下是搜索的结果,当然,笔者是会一一验 ...

  8. Python 模块(五)

    目录 模块介绍 time &datetime模块 random json & picle 一.模块介绍 在我们日常的程序开发过程中,随着代码越写越多,在单个文件里的代码就会越来越长,越 ...

  9. Net FLow Template

    EK  Template : bool bfs(int src, int des){ memset(pre, -, sizeof(pre)); while(!que.empty()) que.pop( ...

  10. Ural 1450 求最长路 SPFA

    题意就是求S点到T点的有向无环图中的最长路. 用SPFA可以解决. 一开始一直RE的原因 QAQ 竟然是在开Edge 邻接表的时候开小了 改了一下4Y #include <stdio.h> ...