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 + ;
int a[maxn][maxn];
int tonext[][] = {{, -}, {-, }};
void dfs(int num, int x, int y, int now) {
a[x][y] = num;
if (x == n && y == n) return;
if (now == ) { //减y的
if (y == && x != n) {
dfs(num + , x + , y, !now);
} else if (x == n) {
dfs(num + , x, y + , !now);
} else {
dfs(num + , x + tonext[now][], y + tonext[now][], now);
}
} else { //减x的
if (x == && y != n) {
dfs(num + , x, y + , !now);
} else if (y == n) {
dfs(num + , x + , y, !now);
} else {
dfs(num + , x + tonext[now][], y + tonext[now][], now);
}
}
}
void work() {
scanf("%d%d%d", &n, &r, &c);
a[][] = ;
dfs(, , , );
// 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 ;
}

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

  1. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  2. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  3. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  4. 2019浙大校赛--A--Thanks, TuSimple!(简单模拟题)

    这题前三段都是一堆吹爆赞助商的屁话,正式题目在图片下边,一个简单模拟题. 题目大意: 有n个男生,m个女生在进行舞会,其中一部分男生祥和比自己矮的女生跳舞,一部分男生想和比自己高的女生跳舞,一部分女生 ...

  5. Gym 100646 Problem C: LCR 模拟题

    Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...

  6. URAL 1993 This cheeseburger you don't need 模拟题

    This cheeseburger you don't need 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1993 Descrip ...

  7. NOIP模拟题汇总(加厚版)

    \(NOIP\)模拟题汇总(加厚版) T1 string 描述 有一个仅由 '0' 和 '1' 组成的字符串 \(A\),可以对其执行下列两个操作: 删除 \(A\)中的第一个字符: 若 \(A\)中 ...

  8. POJ - 1835 宇航员(模拟题)

    问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...

  9. hdu 4706:Children's Day(模拟题,模拟输出大写字母 N)

    Children's Day Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. [HNOI 2010] 弹飞绵羊

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2002 [算法] LCT动态维护森林连通性 时间复杂度 : O(NlogN ^ 2) ...

  2. 如何使用Psyco为你的Python程序提速

    psyco加速Python执行速度的方法:要求: 版本对照:File name      Python versions      Well-tested withpsyco-x.y-win32-py ...

  3. MongoDB复制集成员及架构介绍(一)

    MongoDB复制集介绍 MongoDB支持在多个机器中通过异步复制达到提供了冗余,增加了数据的可用性.MongoDB有两种类型的复制,第一种是同于MySQL的主从复制模式(MongoDB已不再推荐此 ...

  4. 【旧文章搬运】关于在指定进程调用KeUserModeCallback的问题

    原文发表于百度空间,2010-10-07========================================================================== 由于KeU ...

  5. U盘安装 Linux 显示 “Faild to copy file from CD-ROM”

    解决方案 使用 UltraISO 刻录 U盘做镜像时,出现这种情况.查阅别人的 blog,尝试手动挂载发现还是不能成功.然后使用 win32diskimager 重新刻录,再次安装时未出现该情况. 参 ...

  6. E - Lovely Palindromes

    Description Pari has a friend who loves palindrome numbers. A palindrome number is a number that rea ...

  7. 【Hadoop】HDFS笔记(二):HDFS的HA机制和Federation机制

    HA解决了HDFS的NameNode的单点问题: Federation解决了整个HDFS集群中只有一个名字空间,并且只有单独的一个NameNode管理所有DataNode的问题. 一.HA机制(Hig ...

  8. Gym 100851A Adjustment Office (思维)

    题意:给定一个 n*n 的矩阵,然后有 m 个询问,问你每一行或者每一列总是多少,并把这一行清空. 析:这个题不仔细想想,还真不好想,我们可以根据这个题意,知道每一行或者每一列都可以求和公式来求,然后 ...

  9. E20181216-hm

    intersect vt. (指线条.道路等) 相交,交叉; vt. 横断,横切,横穿;

  10. TP5之查询那些事

    1.使用 model 查询,查出的类型为 对象 $a 是一个对象,使用 $a->name 的方式来获取 对象里的属性 2.使用 db 查询,查询出的是 数组 $b 是一个数组,使用 $b['na ...