http://acm.hdu.edu.cn/showproblem.php?pid=4941

给定N,M和K,表示在一个N*M的棋盘上有K个棋子,给出K个棋子的位置和值,然后是Q次操作,对应的是:

1 a b :交换a和b两行

2 a b : 交换a和b两列

3 a b :查询a b这个位置上棋子的值,没有棋子的话输出0

不能直接模拟,对应行列交换,只需交换map映射值,查询时输出map[x],map[y]上值即可

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
struct node {
int x;
int y;
int c;
}; node a[110000]; int main() {
int _;
RD(_);
for (int i = 1; i <= _; i++) {
printf("Case #%d:\n", i);
int n, m, k;
RD2(n,m);RD(k); map<int, int> row;
map<int, int> col;
map<pair<int, int>, int> graph;
for (int i = 0; i < k; i++) {
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].c);
row.insert(make_pair(a[i].x, a[i].x));
col.insert(make_pair(a[i].y, a[i].y));
graph.insert(make_pair(make_pair(a[i].x, a[i].y), a[i].c));
} int T;RD(T);
while (T--) {
int q, x, y;
scanf("%d%d%d", &q, &x, &y);
if (q == 1) {
if (row.find(x) != row.end() && row.find(y) != row.end()) {
swap(row[x], row[y]);
}
}
if (q == 2) {
if (col.find(x) != col.end() && col.find(y) != col.end()) {
swap(col[x], col[y]);
}
}
if (q == 3) {
if (row.find(x) == row.end() || col.find(y) == col.end()) {
puts("0");
} else {
printf("%d\n", graph[make_pair(row[x], col[y])]);
}
}
}
}
return 0;
}

hdu 4941 map的使用的更多相关文章

  1. HDU 4941 Magical Forest(map映射+二分查找)杭电多校训练赛第七场1007

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 解题报告:给你一个n*m的矩阵,矩阵的一些方格中有水果,每个水果有一个能量值,现在有三种操作,第 ...

  2. HDU 4941 Magical Forest 【离散化】【map】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点.每一个点有一个数值.点的xy坐标是0~10^9.点存在于矩阵中.然后 ...

  3. STL : map函数的运用 --- hdu 4941 : Magical Forest

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  4. HDU 4941 Magical Forest --STL Map应用

    题意: 有n*m个格子(n,m <= 2*10^9),有k(k<=10^5)个格子中有值,现在有三种操作,第一种为交换两行,第二种为交换两列,交换时只有两行或两列都有格子有值或都没有格子有 ...

  5. hdu 4941 Magical Forest ( 双重map )

    题目链接 题意: 有一个n*m的田地,里边有k棵树,每棵树的位置为(xi,yi),含有能量值ci.之后又q个询问,分三种; 1)1 a b,将a行和b行交换 2)2 a b,将a列和b列交换 3)3 ...

  6. hdu 4941 stl的map<node,int>用法

    #include<iostream> #include<cstdio> #include<cstring> #include<map> using na ...

  7. hdu 4941 Magical Forest (map容器)

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  8. hdu 4941 Magical Forest

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...

  9. hdu 1075 (map)

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...

随机推荐

  1. PAT 1012 数字分类 (20)(代码+测试点)

    1012 数字分类 (20)(20 分) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求 ...

  2. MySQL连接、登录、密码等

    官方教程:https://dev.mysql.com/doc/refman/8.0/en/ 链接数据库,通过指定 -h 参数可以连接网络上的数据库 mysql -u 用户名 -h 服务器IP -P 端 ...

  3. MySQL 快速复数据库的方法

    为了方便快速复制一个数据库,可以用以下命令将db1数据库的数据以及表结构复制到newdb数据库 创建新的数据库 #mysql -u root -p123456 mysql>CREATE DATA ...

  4. TP QQ 微信 微博登录

    use Org\Util\QQconnect; use Org\Util\Wechatauth; use Org\Util\SaeTOAuthV2; use Org\Util\SaeTClientV2 ...

  5. robotframework 常用关键字

    标准库 第三方库 其他库

  6. 带token的get和post方法

    GET和POST传值失败,多半是传输的字符串和URL的事 public static string ExcuteGetToken(string serviceUrl, string ReqInfo, ...

  7. Python 使用for...in...和 while 循环 实现8种格式的 九九乘法表

    #九九乘法表 for...in .. #左下角 for i in range(1,10): for j in range(1,i+1): print(' %d×%d=%2d'%(j,i,i*j), e ...

  8. mybatis学习 十 动态 SQL

    1.  根据方法传入的参数不同执行不同的 SQL 命令.称为动态 SQL, MyBatis 中动态 SQL 就是在 mapper.xml 中添加逻辑判断等. 2. <if>标签 <s ...

  9. UDDI

    什么是 UDDI? UDDI 是一个独立于平台的框架,用于通过使用 Internet 来描述服务,发现企业,并对企业服务进行集成. UDDI 指的是通用描述.发现与集成服务 UDDI 是一种用于存储有 ...

  10. web前端面试题库

    web前端面试题及答案   1.常用那几种浏览器测试?有哪些内核(Layout Engine)? 答: (Q1) 浏览器:IE,Chrome,FireFox,Safari,Opera.    (Q2) ...