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. javascript 高级程序设计 七

    引言:好几天没有写随笔了,项目有点紧,恰好今天项目遇到了比较大阻塞,就只好来写一篇随笔来压压惊. 1.Date类型 创建一个新的Date:(除了new Date()外) var someDate = ...

  2. linux系统web站点设置-http基础设置

    一.httpd2.2的组成: /etc/httpd:服务器的根目录 conf/httpd.conf,conf.d/*:配置文件 conf/magic:MIME的配置文件 logs:日志文件的存放路径, ...

  3. spring自动注解Autowired配置

    1.spring注解:http://blog.csdn.net/xyh820/article/details/7303330/ 2.最简ssm配置:http://blog.csdn.net/qq_18 ...

  4. iOS 3D Touch功能

    新的触摸体验——iOS9的3D Touch 一.引言 在iphone6s问世之后,很多果粉都争先要体验3D Touch给用户带来的额外维度上的交互,这个设计之所以叫做3D Touch,其原理上是增加了 ...

  5. BZOJ 1093 [ZJOI2007]最大半连通子图 - Tarjan 缩点

    Description 定义一个半联通图为 : 对任意的两个点$u, v$,都有存在一条路径从$u$到$v$, 或从$v$到$u$. 给出一个有向图, 要求出节点最多的半联通子图,  并求出方案数. ...

  6. [Python]Python章1 Python中_的故事

    _xx 单下划线开头 Python中没有真正的私有属性或方法,可以在你想声明为私有的方法和属性前加上单下划线,以提示该属性和方法不应在外部调用.如果真的调用了也不会出错,但不符合规范. 本文为译文,版 ...

  7. 隐马尔科夫_HMM

    有向图 抽象:λ代表输入:输入一个句子,λi表示句子中的每个字 O代表输出:[B词首/M词中/E词尾/S单独成词] max=maxP(O1 O2 On/ λ1 λ2 λn) 假设: (1)当前观察值只 ...

  8. Git/Github的使用并与Eclipse整合(zz)

    Git/Github的使用并与Eclipse整合 您的评价:          收藏该经验       Git简介 Git是一个免费的.分布式的版本控制工具,或是一个强调了速度快的源代码管理工具.每一 ...

  9. 46.UISearchBar的placeholder字体颜色和背景颜色

    1.改变searchbar的searchField属性 UITextField *searchField = [searchbar valueForKey:@"searchField&quo ...

  10. php使用include报错require_once(../include.php): failed to open stream: No such file or directo

    引入路径的问题,建议加入include_once $_SERVER['DOCUMENT_ROOT']."/include.php";意思是获取网站根目中的include.php 截 ...