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. Iperf使用方法与参数说明

      Iperf使用方法与参数说明 http://pkgs.repoforge.org/iperf/ Iperf是一个网络性能测试工具.可以测试TCP和UDP带宽质量,可以测量最大TCP带宽,具有多种参 ...

  2. cent 7 安装VNC

    1. yum install tigervnc-server; 2.cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncs ...

  3. 02. pt-archiver

    pt-archiver \--source h=192.168.100.101,P=3306,u=admin,p='admin',D=db01,t=t01 \--dest h=192.168.100. ...

  4. windows无法停止 服务 错误1053 服务没有及时响应

    windows无法停止 服务 错误1053 服务没有及时响应 服务程序.exe -st

  5. Creating Your Own PHP Helper Functions In Laravel

    By Hamza Ali LAST UPDATED AUG 26, 2018  12,669 104 Laravel provides us with many built-in helper fun ...

  6. Partition Array into Disjoint Intervals LT915

    Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...

  7. jquery plugin 之 form表单验证插件

    基于h5表单验证系统.扩展了对easyui组件的支持 先上图: 提示样式用到了伪对象的 {content: attr(xxx)}函数方法,实现提示信息能动态切换. 1.关键属性说明: type: 表单 ...

  8. java基本知识归集

    类中可以有几种东西:属性,方法,构造器,初始化块 new创建对象时, 1.类属性和类初始化块分配空间. 2.执行默认初始化 如有父类,先为父类执行父类自己的1和2步骤,再执行上面的1和2. 一个类执行 ...

  9. R语言2版本3版本安装

    ./configure --prefix=/YZpath/public/software/R/R-3.5.0 --with-readline=no --with-x=no make make inst ...

  10. AJAX-php-json数组

    1.在php中有个数组,响应回前端 $array=["习大大","川普","金三胖"];2.JS对象数据格式 ex: 数组: var TOM ...