zoukankan      html  css  js  c++  java
  • SDUT 1068-Number Steps(数学:直线)

    Number Steps

    Time Limit: 1000ms   Memory limit: 10000K  有疑问?点这里^_^

    题目描写叙述

    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.

    输入

    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.

    输出

    For each point in the input, write the number written at that point or write No Number if there is none.

    演示样例输入

    3
    4 2
    6 6
    3 4

    演示样例输出

    6
    12
    No Number
    就是按图中的规律给出两条直线。。

    我一開始竟然没看出来是直线。。找规律打表敲了一大片结果wa了,后来发现就是推断点是否在直线上嘛 两条直线分别为y=x与y=x-2; 然后那个编号能够依据坐标x写出相应关系,非常好写,都是等差数列。我是分奇偶讨论的。。

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cctype>
    #include <cmath>
    #include <cstdlib>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #define ll long long
    using namespace std;
    const int INF=1<<27;
    const int maxn=1010;
    int main()
    {
    	int x,y,n;
    	scanf("%d",&n);
    	while(n--)
    	{
    		scanf("%d%d",&x,&y);
    		if(x==y)
    		{
    			if(x%2)
    				printf("%d
    ",2*x-1);
    			else
    				printf("%d
    ",2*x);
    		}
    		else if(y==x-2)
    		{
    			if(x%2)
    				printf("%d
    ",2*x-3);
    			else
    				printf("%d
    ",2*x-2);
    		}
    		else
    			puts("No Number");
    	}
        return 0;
    }
    


    
    
  • 相关阅读:
    tomcat拒绝接收请求记录
    js阻止事件冒泡
    BZOJ 5381 or & Codeforces 623E Transforming Sequence DP+NTT
    BZOJ5384 有趣的字符串题 回文树
    Codeforces 932G Palindrome Partition 回文树+DP
    LOJ2542 随机游走 Min-Max容斥+树上期望DP
    LOJ6070 基因 分块+回文自动机
    BZOJ3682 Phorni 后缀平衡树
    Codeforces 994F Compute Power 二分+DP
    BZOJ2759一个动态树好题 LCT
  • 原文地址:https://www.cnblogs.com/lytwajue/p/6828957.html
Copyright © 2011-2022 走看看