题目连接

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. ASP.NET MVC4 学习系统三(控制器Controller)

    控制器(Controllers)    在MVC架构模式的上下文里,控制器响应用户的输入(比如,用户点击“保存”按钮),并协调模型.视图以及(经常)数据访问层.在ASP.NET MVC程序里,控制器就 ...

  2. flask-admin

    初始化 class Admin(app=None, name=None, url=None, subdomain=None, index_view=None, translations_path=No ...

  3. WWF3的持续化<第五篇>

    WWF提供的持续化功能会自动记录工作流实例以及它包含的所有活动的执行状态,这些状态并不是指工作流上流转的表单所呈现的业务逻辑状态.WWF持续化功能就是将未执行完成的工作流实例以及该实例中各种活动的状态 ...

  4. 【MySQL】MySQL/MariaDB的优化器对in子查询的处理

    参考:http://codingstandards.iteye.com/blog/1344833 上面参考文章中<高性能MySQL>第四章第四节在第三版中我对应章节是第六章第五节 最近分析 ...

  5. Handler 取不到session 解决办法

      Handler需要继承 Handler : IHttpHandler, IReadOnlySessionState, IRequiresSessionState

  6. php 导出csv

    public function doworks(){        //输出Excel文件头,可把user.csv换成你要的文件名        header('Content-Type: appli ...

  7. 移动端的头部标签和meta

    <!DOCTYPE html><!--HTML5 doctype--> <html> <head> <title>xxx</title ...

  8. LLVM language 参考手册(译)(3)

    可见性模式(Visibility Styles) 所有全局变量和函数具有以下的可见性模式之一: “default” - Default style 在那些使用ELF object file格式的平台( ...

  9. 设计模式-外观模式(Facade)

    简介 外观模式(Facade),将外部与内部子系统的通信通过一个统一的门面对象进行. 由两部分组成: 门面角色:供外部调用,内部可能组装了多个子系统,多个方法. 子系统角色:子系统的方法也可以直接供外 ...

  10. linux查找日志常用命令

    1.查找文件test中目标字符串(xxxx)出现的行数位置grep -n xxxx  test 2.文件test从某一行(n)开始显示more +n  test 3.查询文件test中出现目标字符串x ...