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 + ;
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 模拟题的更多相关文章
- 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中
题目名称 正确答案 序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- 2019浙大校赛--A--Thanks, TuSimple!(简单模拟题)
这题前三段都是一堆吹爆赞助商的屁话,正式题目在图片下边,一个简单模拟题. 题目大意: 有n个男生,m个女生在进行舞会,其中一部分男生祥和比自己矮的女生跳舞,一部分男生想和比自己高的女生跳舞,一部分女生 ...
- Gym 100646 Problem C: LCR 模拟题
Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...
- 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 ...
- NOIP模拟题汇总(加厚版)
\(NOIP\)模拟题汇总(加厚版) T1 string 描述 有一个仅由 '0' 和 '1' 组成的字符串 \(A\),可以对其执行下列两个操作: 删除 \(A\)中的第一个字符: 若 \(A\)中 ...
- POJ - 1835 宇航员(模拟题)
问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...
- hdu 4706:Children's Day(模拟题,模拟输出大写字母 N)
Children's Day Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- ansible使用中遇到的问题
前提是,可以ssh无秘钥过去,但是使用ansible就报这个错误, 正在找造成的原因及解决方法 第一步, 明白了,,如何已经打通ssh无秘钥后,就不能再 hosts中加入ansible_ssh_pas ...
- ES6 新特性之Symbol
Symbol let s1 = Symbol('foo'); let s2 = Symbol('bar'); s1 // Symbol(foo) s2 // Symbol(bar) s1.toStri ...
- tomcat正常启动,但是java项目没有启动原因
右键项目,选择properties,查看该属性配置的是否正确
- legend2---开发日志12(vue如何进一步学习)
legend2---开发日志12(vue如何进一步学习) 一.总结 一句话总结:还是得找教程(比如视频),自己摸索太浪费时间,也容易踩坑和抓不住重点 还是得找教程(比如视频),自己摸索太浪费时间,也容 ...
- Understand JavaScript’s “this” With Clarity, and Master It
The this keyword in JavaScript confuses new and seasoned JavaScript developers alike. This article a ...
- 004 - 修改Pycharm默认启动打开最近的项目
随着项目的增多, 可能会使用到不同的项目, 而有的时候我们导入项目到新一个窗口中之后, 下一次打开Pycharm就变成之前导入的那个项目了 那么之前我们的项目怎么找到呢? 修改一下Pycharm启动默 ...
- VS2008中使用JSONCPP方法小结
Introduction JSON (JavaScript Object Notation) is a lightweight data-interchange format. It can repr ...
- python下载各大主流视频网站电影
You-Get 是一个命令行工具, 用来下载各大视频网站的视频, 是我目前知道的命令行下载工具中最好的一个, 之前使用过 youtube-dl, 但是 youtube-dl 吧, 下载好的视频是分段的 ...
- ubuntu16.04 + cuda9.0(deb版)+Cudnn7.1
https://blog.csdn.net/Umi_you/article/details/80268983
- mysql函数之七:replace() MySQL批量替换指定字段字符串
mysql replace实例说明: UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def'); REPLACE(str,from_str,to_str) 在字符串 st ...