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. andorid 列表视图之SimpleAdapter

    .xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android=&qu ...

  2. How to program BMW KOMBI and NBTwith ENET E sys cable ICOM A2

    This is how to set up Router or DHCP server for BMW KOMBI and NBT programming with Enet e sys cable ...

  3. BZOJ2330或洛谷3275 [SCOI2011]糖果

    BZOJ原题链接 洛谷原题链接 很明显的差分约束,但数据范围较大,朴素\(SPFA\)判正环求解会\(T\)(理论上如此,但我看到有挺多人用朴素的还跑得挺快..),所以需要优化. 我们所建立的有向图中 ...

  4. 20172325 2018-2019-2 《Java程序设计》第四周学习总结

    20172325 2018-2019-2 <Java程序设计>第四周学习总结 教材学习内容总结 <Java软件结构与数据结构>第六章-列表 一.概述 1.列表是什么? 列表集合 ...

  5. VisualStudio使用技巧

    控制台工程去除黑框 刚学习OpenGL,绘制图形的时候,如果不进行设置,运行的时候会先出现黑窗口再出现Windows窗口.其实要去除控制台窗口非常简单,只需要修改工程设置,把子系统改成Windows, ...

  6. python 计时程序运行时间

    import time time_start=time.time() time_end=time.time() print('totally cost',time_end-time_start)

  7. [Robot Framework] Jenkins上调用Rebot命令时执行报错不往下执行其他命令

    在配置jenkins job时,添加构建步骤Execute Windows batch command,输入执行rebot命令 报错信息: Call C:\Python27\Scripts\rebot ...

  8. c++11 并发 条件变量 超时等待的代码练习

    资料地址 http://en.cppreference.com/w/cpp/thread/condition_variable/wait_until http://www.cnblogs.com/ha ...

  9. Android Studio Tip of the Day

    1. Alt + Q 可以查看一个方法的简单参数列表. 2. 查看一个类,如果是eclipse的话,一般直接是F3, 现在的F3好痛苦.只能改为Ctrl + H,将就着用. 3. Ctrl + J 语 ...

  10. maven mirror , profile , snapshot 和release

    1. settings.xml 配置的mirror <mirrors> <mirror> <id>Nexus</id> <name>nexu ...