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. c/c++通用内存泄漏检测框架GMFD(General Memory Fault Detection Framework)

    http://qa.baidu.com/blog/?p=171 1 背景: x86平台有完善的用户态检测内存工具比如valgrind等,可以监控程序运行中详细的内存信息,从而精确定位内存问题.然而随着 ...

  2. requireJS 加载css、less文件

    -- requireJS 同样可以加载css 文件,有require-css的插件,只需要把插件放入main.js同文件夹,在依赖处 采用 ‘css! test.css’的形式就可以加载css文件 - ...

  3. RequireJS 配置理解

    RequireJS 配置: 1.首先加载RequireJS文件 <script src="//cdn.bootcss.com/require.js/2.1.22/require.js& ...

  4. hex2bin

    typedef BYTE unsigned char; </pre><pre code_snippet_id="1639451" snippet_file_nam ...

  5. button的FlatStyle和FlatAppearance属性

    FlatStyle是处理边框的样式,而FlatAppearance是用来设置边框的颜色,宽度和鼠标移动和点击时的效果设置FlatStyle为Flat,并且设置FlatAppearance下的Borde ...

  6. 如何在ubuntu下使用windows下的程序(eg: .exe)

    为了在ubutu下安装百度云管家,上网查了下如何在ubuntu 下安装.exe文件,其中遇到一些问题记录如下: 使用的命令: 开始时直接使用的sudo apt-get install wine 在运行 ...

  7. java 随机颜色

    用HSV模型来实现颜色的随机,然后转为RGB模型 色相(H)是色彩的基本属性,就是平常所说的颜色名称,如红色.黄色等. 饱和度(S)是指色彩的纯度,越高色彩越纯,低则逐渐变灰,取0-100%的数值. ...

  8. hdu-1181

    变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submis ...

  9. Qt .pro文件配置大全!

    避免以后的无意义重复劳动,将用过的所有的头文件库文件的配置都放在这里,以后要用的话直接copy就好. eigen3: INCLUDEPATH += \ /usr/local/include/eigen ...

  10. 3-2if条件结构

    不同条件做不同的操作.例如满100就减去20 条件结构 package com.imooc.operator; public class ConditionDemo1 { public static ...