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. Activity的onSaveInstanceState()和onRestoreInstanceState()以及API详解

    为了弄清楚onSaveInstanceState()方法和onRestoreInstanceState()方法,我翻译一下谷歌的API,翻译如下: There are a few scenarios ...

  2. 友盟iOS微信登陆没有回调的原因

    1.在友盟文档中这样说: 链接 7.4 微信登录 添加配置文件参考文档:添加微信及朋友圈,添加相关库文件,配置URL schemes及添加系统回调 注意微信登录必须先在微信开放平台申请微信登录权限 在 ...

  3. BZOJ 2134: 单选错位( 期望 )

    第i个填到第i+1个的期望得分显然是1/max(a[i],a[i+1]).根据期望的线性性, 我们只需将每个选项的期望值累加即可. ---------------------------------- ...

  4. Spring IOC三种注入方式(接口注入、setter注入、构造器注入)(摘抄)

    IOC ,全称 (Inverse Of Control) ,中文意思为:控制反转, Spring 框架的核心基于控制反转原理. 什么是控制反转?控制反转是一种将组件依赖关系的创建和管理置于程序外部的技 ...

  5. python下载文件(图片)源码,包含爬网内容(爬url),可保存cookie

    #coding=utf-8 ''' Created on 2013-7-17 @author: zinan.zhang ''' import re import time import httplib ...

  6. c++ 重载,覆盖,重定义 2

    前一篇 http://www.cnblogs.com/iois/p/4085173.html 写有些地方不够准确,重新整理了一遍 函数重载(Function Overloading) C++允许同一范 ...

  7. C++变量(C++变量定义、变量赋值、命名规则)

    其实在前面的例子中已经多次用到了变量.在程序运行期间其值可以改变的量称为变量.一个变量应该有一个名字,并在内存中占据一定的存储单元,在该存储单元中存放变量的值.请注意区分变量名和变量值这两个不同的概念 ...

  8. Matlab中S函数建立与应用

    function [sys,x0,str,ts] = sfuntmpl(t,x,u,flag) % SFUNTMPL 是M-文件 S函数模板 %  通过剪裁,用户可以生成自己的S函数,不过一定要重新命 ...

  9. LVS--什么是LVS?

    1.什么是LVS? 首先简单介绍一下LVS (Linux Virtual Server)到底是什么东西,其实它是一种集群(Cluster)技术,采用IP负载均衡技术和基于内容请求分发技术.调度器具有很 ...

  10. mysql入门记录

    mysql -h localhost(or ID) -u root -p show databases; create database <数据库名>: drop database < ...