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 ...
随机推荐
- tflearn 中文汉字识别模型试验汇总
def get_model(width, height, classes=40): # TODO, modify model # Building 'VGG Network' network = in ...
- 万亿级日志与行为数据存储查询技术剖析(续)——Tindex是改造的lucene和druid
五.Tindex 数果智能根据开源的方案自研了一套数据存储的解决方案,该方案的索引层通过改造Lucene实现,数据查询和索引写入框架通过扩展Druid实现.既保证了数据的实时性和指标自由定义的问题,又 ...
- 多线程之:synchonized锁实现的原理<一>
一:java同步的锁类型? --->目前在Java中存在两种锁机制:synchonized和Lock--->Lock接口及其实现类是JDK5增加的内容,其作者是大名鼎鼎的并发专家Doug ...
- HDU1496(巧妙hash)
Equations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ1742(多重部分和问题:模板题)
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 32776 Accepted: 11131 Descripti ...
- $bzoj4569$
$st表+并查集$ $考虑暴力方法:我们每次将对应相等的位置用并查集连起来,那么最终答案就是9*10^{连通块个数-1}$ $很明显上面这个办法过不去,问题在于重复次数太多了,如果一个区间已经对应相等 ...
- ubuntu_ root change to user
(1)从user用户切换到root用户 不管是用图形模式登录Ubuntu,还是命令行模式登录,我们会发现缺省的用户是user 但是当我们需要执行一些具有root权限的操作(如修还系统文件)时,经常需要 ...
- 3、webpack打包出的文件解析
分析打包后的结果,看看打包后的结果是什么东西 把打包后的结果.注释什么的删删‘’ 当前是一个匿名函数. 默认的时候会执行,执行的时候会传一个对象,对象有几部分,第一部分是我们的key.第二部分是我们的 ...
- (水题)HDU - 1077 - Catching Fish - 计算几何
http://acm.hdu.edu.cn/showproblem.php?pid=1077 很明显这样的圆,必定有两个点在边界上.n平方枚举圆,再n立方暴力判断.由于没有给T,所以不知道行不行.
- angularjs 切换tab页的一个方法
tab条的 css: .floor-tab-li { float: left; padding: 6px 12px; font-size: 14px; font-weight: normal; lin ...