18002 Z-Scan 模拟题

18002 Z-Scan

时间限制:1000MS  内存限制:65535K
提交次数:0 通过次数:0

题型: 编程题   语言: 不限定

Description

Z-Scan is a method to scan data in a square matrix(矩阵). Fig.1 shows Z-Scan. Here, the number stands for
the scan sequence number of the element.

Our question is 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 sequence number of the element?

输入格式

The first line is an integer N, the number of cases, 1<=N<=10
N 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 element. The "c" is the column of the element.  1 <= r, c <= n <= 100 

输出格式

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

输入样例

3
5 1 2
5 4 5
99 99 99

输出样例

2
23
9801

来源

Mr. Chen

作者

admin

模拟题打表,模拟的时候用dfs模拟

注意到只有两种方向,

一种是x + 1, y - 1

一种是x - 1, y + 1

其他那些向下和向左,是作为边界来处理的。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;

#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
int n, r, c;
const int maxn = 1e2 + 20;
int a[maxn][maxn];
int tonext[2][2] = {{1, -1}, {-1, 1}};
void dfs(int num, int x, int y, int now) {
    a[x][y] = num;
    if (x == n && y == n) return;
    if (now == 0) { //减y的
        if (y == 1 && x != n) {
            dfs(num + 1, x + 1, y, !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 { //减x的
        if (x == 1 && y != n) {
            dfs(num + 1, x, y + 1, !now);
        } else if (y == n) {
            dfs(num + 1, x + 1, y, !now);
        } else {
            dfs(num + 1, x + tonext[now][0], y + tonext[now][1], now);
        }
    }
}
void work() {
    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]);
}

int main() {
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    int t;
    scanf("%d", &t);
    while (t--) work();
    return 0;
}
时间: 2024-08-24 20:58:58

18002 Z-Scan 模拟题的相关文章

Gym 100625C 密文匹配-模拟题-(map)

题意:已知n个明文和一个密文,推出可能的匹配关系,然后输出字符串ss的密文. 分析: 一个模拟题,当时想偏了,还想着要同一字母可能在任意位置,然后要记录每个字母的位置,找密文的相应位置必须是同一字母,balabala的,不知道什么鬼. 其实就是简单的对应关系,不用管位置啥的,只管同一字母对应的密文是一样的就行了.26个字母,枚举一遍就是了.对应关系匹配啥的用map是最好不过的了.小tirck是,如果已知25个字母,那么剩下的一个也就知道了. 代码: #include<iostream> #in

[xyz模拟题]动态维护树的直径

专出神题的xyz. 支持删加边.修改点权.维护树的直径. LCT 需要额外记录子树信息.用一个堆维护. #include<cstdio> #include<cstring> #include<algorithm> #include<set> #include<vector> #include<queue> using namespace std; #define rep(i,x,y) for(i=x;i<=y;i++) #def

又是一道模拟题吧!

题目如下:This cheeseburger you don't need Description Yoda: May the Force be with you. Master Yoda is the oldest member of the Jedi Council. He conducts preparatory classes of little Younglings up to the moment they get a mentor. All Younglings adore mas

OCJP(1Z0-851) 模拟题分析(五)

Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有疏漏,还请大家对我的分析提出质疑. QUESTION 134 Given:11. class Snoochy {12. Boochy booch;13. public Snoochy() { booch = new Boochy(this); }14. }15.16. class Boochy {1

OCJP(1Z0-851) 模拟题分析(六)

Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有疏漏,还请大家对我的分析提出质疑. QUESTION 167Given:1. import java.util.*;2. public class WrappedString {3. private String s;4. public WrappedString(String s) { this.

8.22 NOIP 模拟题

  8.22 NOIP 模拟题 编译命令 g++ -o * *.cpp gcc -o * *.c fpc *.pas 编译器版本 g++/gcc 4.9.2 fpc 2.6.2 评测环境 64 位 Linux, 3.3GHZ CPU 评测软件 Lemon 评测方式 忽略行末空格和回车 特别注意:c/c++ 选手使用 printf 输出 64 位整数请使用%lld 1 注意事项 A 债务 文件名                            输入文件             输出文件  

OCJP(1Z0-851) 模拟题分析(二)

Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有疏漏,还请大家对我的分析提出质疑. QUESTION 31 Given:1. interface A { public void aMethod(); }2. interface B { public void bMethod(); }3. interface C extends A,B { pub

HDU 4028 The time of a day STL 模拟题

暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; #define ll __int64 #define N 42 ll n,m,ans;

cf428c 模拟题

这题说的是给了 n个数然后又 k次 的交换任意位置的 数字的机会  计算最长的连续子序列的和 这要撸  模拟整个 过程 并不能就是算最长的递增序列 如果只是 找最长的 和序列的 话 会存在 很多问题 在替换的时候 每一个决策 都影响着 下一个决策  这样 存在谁与谁替换 这样的状态有 200!种    那就枚举每个区间这样就可以使得 我们所用替换方法得当  因为在替换中我们进行替换是对不同区间的 操作 比如 在替换序列之内的 数字的时候 其实操作的就是不同的区间 与外面的序列进行替换的时候 操作