18002 Z-scan Simulation problem

Source: Internet
Author: User

18002 Z-scan

Time limit: 1000MS memory limit: 65535K
Number of submissions: 0 Number of Passes: 0

Question types: programming language: not Limited

Description
Z-scan is a method to the Scan data in a square matrix (matrix). Fig.1 shows Z-scan. Here, the number stands for the scan sequence number of the element.
Our question are very simple. Given the size (n * n) of the square matrix and the row and column of the matrix element, could you tell me the scan seque NCE number of the element?




Input format
The first line was an integer N, the number of cases, 1<=n<=10n lines follow. Each line contains 3 integers (n r c), the ' n ' stands for a square matrix in size of n * n.the ' R ' is the row of the Elemen T. The "C" is the column of the element.  



Output format
For each case, output the scan sequence number of the element.



Input sample
35 1 25 4 599 99 99



Output sample
2239801



Source

Mr Chen

Author

Admin

Simulate a table, simulate the time with DFS simulation

Notice that there are only two directions,

One is X + 1, y-1

One is x-1, Y + 1

The other ones go down and to the left, and are treated as borders.

#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#defineIOS Ios::sync_with_stdio (False)using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>intN, R, C;Const intMAXN = 1e2 + -;intA[MAXN][MAXN];inttonext[2][2] = {{1, -1}, {-1,1}};voidDfsintNumintXintYintNow ) {A[x][y]=num; if(x = = N && y = = N)return; if(now = =0) {//minus Y.        if(Y = =1&& x! =N) {dfs (num+1, X +1Y!Now ); } Else if(x = =N) {dfs (num+1, X, Y +1, !Now ); } Else{dfs (num+1, X + tonext[now][0], Y + tonext[now][1], now); }    } Else{//minus X.        if(x = =1&& Y! =N) {dfs (num+1, X, Y +1, !Now ); } Else if(Y = =N) {dfs (num+1, X +1Y!Now ); } Else{dfs (num+1, X + tonext[now][0], Y + tonext[now][1], now); }    }}voidWork () {scanf ("%d%d%d", &n, &r, &c); a[1][1] =1; DFS (2,1,2,0);//for (int i = 1; I <= n; ++i) {//For (int j = 1; j <= N; ++j) {//printf ("%d", a[i][j]);//        }//printf ("\ n");//    }printf"%d\n", A[r][c]);}intMain () {#ifdef local freopen ("Data.txt","R", stdin);#endif    intT; scanf ("%d", &t);  while(t--) work (); return 0;}

18002 Z-scan Simulation problem

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.