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)