题目连接

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

Magical Forest

Description

There is a forest can be seen as $N * M$ grid. In this forest, there is some magical fruits, These fruits can provide a lot of energy, Each fruit has its location$(X_i, Y_i)$ and the energy can be provided $C_i$.

However, the forest will make the following change sometimes:
1. Two rows of forest exchange.
2. Two columns of forest exchange.
Fortunately, two rows(columns) can exchange only if both of them contain fruits or none of them contain fruits.

Your superior attach importance to these magical fruit, he needs to know this forest information at any time, and you as his best programmer, you need to write a program in order to ask his answers quick every time.

Input

The input consists of multiple test cases.

The first line has one integer $W.$ Indicates the case number.$(1 \leq W \leq 5)$

For each case, the first line has three integers $N, M, K.$ Indicates that the forest can be seen as maps $N$ rows, $M$ columns, there are $K$ fruits on the map.$(1 \leq N, M \leq 2*10^9,\ 0 \leq K \leq 10^5)$

The next $K$ lines, each line has three integers $X, Y, C,$ indicates that there is a fruit with $C$ energy in $X$ row, $Y$ column. $(0 \leq X \leq N-1,\ 0 \leq Y \leq M-1,\ 1 \leq C \leq 1000)$

The next line has one integer $T.$ $(0 \leq T \leq 10^5)$
The next T lines, each line has three integers $Q, A, B.$
If $Q = 1$ indicates that this is a map of the row switching operation, the $A$ row and $B$ row exchange.
If $Q = 2$ indicates that this is a map of the column switching operation, the $A$ column and $B$ column exchange.
If $Q = 3$ means that it is time to ask your boss for the map, asked about the situation in $(A, B)$.
(Ensure that all given $A, B$ are legal. )

Output

For each case, you should output "Case #C:" first, where C indicates the case number and counts from 1.

In each case, for every time the boss asked, output an integer X, if asked point have fruit, then the output is the energy of the fruit, otherwise the output is 0.

Sample Input

1
3 3 2
1 1 1
2 2 2
5
3 1 1
1 1 2
2 1 2
3 1 1
3 2 2

Sample Output

Case #1:
1
2
1

map映射。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::swap;
using std::sort;
using std::set;
using std::map;
using std::pair;
using std::vector;
using std::multiset;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int Max_N = ;
typedef unsigned long long ull;
struct Node {
int x, y, val;
Node(int i = , int j = , int k = ) :x(i), y(j), val(k) {}
inline bool operator<(const Node &a) const {
return x == a.x ? y > a.y : x > a.x;
}
};
set<Node> st;
set<Node>::iterator ite;
map<int, int> x, y;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int t, n, m, a, b, v, q, k, p = ;
scanf("%d", &t);
while (t--) {
st.clear(), x.clear(), y.clear();
scanf("%d %d %d", &n, &m, &k);
while (k--) {
scanf("%d %d %d", &a, &b, &v);
if (x.find(a) == x.end()) x[a] = a;
if (y.find(b) == y.end()) y[b] = b;
st.insert(Node(a, b, v));
}
printf("Case #%d:\n", p++);
scanf("%d", &k);
while (k--) {
scanf("%d %d %d", &q, &a, &b);
if ( == q) {
if (x.find(a) == x.end()) x[a] = a;
if (x.find(b) == x.end()) x[b] = b;
swap(x[a], x[b]);
} else if ( == q) {
if (y.find(a) == y.end()) y[a] = a;
if (y.find(b) == y.end()) y[b] = b;
swap(y[a], y[b]);
} else {
ite = st.find(Node(x[a], y[b]));
printf("%d\n", ite == st.end() ? : ite->val);
}
}
}
return ;
}

hdu 4941 Magical Forest的更多相关文章

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

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

  2. hdu 4941 Magical Forest (map容器)

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

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

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

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

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

  5. HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)

    思路:将行列离散化,那么就可以用vector 存下10W个点 ,对于交换操作 只需要将行列独立分开标记就行   . r[i] 表示第 i 行存的是 原先的哪行         c[j] 表示 第 j ...

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

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

  7. 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 ...

  8. HDU 4941 Magical Forest (Hash)

    这个题比赛的时候是乱搞的,比赛结束之后学长说是映射+hash才恍然大悟.因此决定好好学一下hash. 题意: M*N的格子,里面有一些格子里面有一个值. 有三种操作: 1.交换两行的值. 2.交换两列 ...

  9. hdu4941 Magical Forest (stl map)

    2014多校7最水的题   Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit ...

随机推荐

  1. 安装Oracle软件

    1.安装linux操作系统和VMware Tools 2.创建组和用户,以root用户运行以下命令: groupadd -g 1000 oinstall groupadd -g 1001 dba us ...

  2. 如何在MAC机器中实现移动设备WiFI上网(没有专门的无线路由器的情况)

    在很多办公室甚至家中都有无线路由器以方便通过WIFI信号上网.如果没有无线路由器,如何让多个移动智能终端同时上网呢?如果你是Windows用户那么可以选择wifi共享精灵来解决,如果你拥有MAC机器, ...

  3. C++ Namespace 详解

    命名空间的定义格式为:(取自C++标准文档) named-namespace-definition: namespace identifier { namespace-body } unnamed-n ...

  4. (笔记)angular选中变色

  5. hbase日常操作及维护

    一,基本命令: 建表:create 'testtable','coulmn1','coulmn2' 也可以建表时加coulmn的属性如:create 'testtable',{NAME => ' ...

  6. Cent OS yum 安装 Adobe flash player

    桌面打开浏览器访问:http://get.adobe.com/cn/flashplayer/.网页会判断操作系统和浏览器并下载 Flash Player(支持Firefox浏览器). 或者直接下载: ...

  7. eclipse自动补全

    最简单的修改方式是:Windows——>Preferences——>Java-->Editor-->Content Asist,在Auto activation trigger ...

  8. 软件工程 speedsnail 第二次冲刺5

    20150522 完成任务:蜗牛帧数变化已经实现,行走的蜗牛具有了动态的视觉效果: 遇到问题: 问题1 帧数大小根据人眼来设置 解决1 除29余0到14的为第一帧 明日任务: 蜗牛碰撞身体翻转

  9. always pick the choice that scares you a little

    “One of my philosophies is to always pick the choice that scares you a little. The status quo, the p ...

  10. Win7下安装IEWebControls.msi

    编写人:CC阿爸 2014-2-22 IEWebControls.msi是发布在.net 1.1时代.微软为弥布.net控件的不足而发布一组控件.很多程序猿都喜欢用到他. 方法一: 首先保证IIS7安 ...