Sdut 1068-number steps (Mathematics: Straight Line)

Source: Internet
Author: User
Number steps Time Limit: 1000 ms memory limit: 10000 k any questions? Click Here ^_^ Starting from point () 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 (), (), 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. enter 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
34 26 63 4
Sample output
612No Number
Is to give two straight lines according to the law in the graph .. I didn't see a straight line at first .. Find the regular expression knocked on a large piece of Results wa, and later found that is to judge whether the point is in a straight line, the two straight lines are Y = x and y = X-2; then the number can be used to write the corresponding relationship according to coordinate X. It is easy to write. It is an arithmetic difference series. I will discuss the parity ..
#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 longusing 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\n",2*x-1);elseprintf("%d\n",2*x);}else if(y==x-2){if(x%2)printf("%d\n",2*x-3);elseprintf("%d\n",2*x-2);}elseputs("No Number");}    return 0;}


 

Sdut 1068-number steps (Mathematics: Straight Line)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.